Search in sources :

Example 6 with NetworkExternalLoadBalancerVO

use of com.cloud.network.dao.NetworkExternalLoadBalancerVO in project cloudstack by apache.

the class ExternalLoadBalancerDeviceManagerImpl method getExternalLoadBalancerForNetwork.

@Override
public ExternalLoadBalancerDeviceVO getExternalLoadBalancerForNetwork(Network network) {
    NetworkExternalLoadBalancerVO lbDeviceForNetwork = _networkExternalLBDao.findByNetworkId(network.getId());
    if (lbDeviceForNetwork != null) {
        long lbDeviceId = lbDeviceForNetwork.getExternalLBDeviceId();
        ExternalLoadBalancerDeviceVO lbDeviceVo = _externalLoadBalancerDeviceDao.findById(lbDeviceId);
        assert (lbDeviceVo != null);
        return lbDeviceVo;
    }
    return null;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) NetworkExternalLoadBalancerVO(com.cloud.network.dao.NetworkExternalLoadBalancerVO)

Example 7 with NetworkExternalLoadBalancerVO

use of com.cloud.network.dao.NetworkExternalLoadBalancerVO in project cloudstack by apache.

the class ExternalLoadBalancerDeviceManagerImpl method findSuitableLoadBalancerForNetwork.

@Override
public ExternalLoadBalancerDeviceVO findSuitableLoadBalancerForNetwork(Network network, boolean dedicatedLb) throws InsufficientCapacityException {
    long physicalNetworkId = network.getPhysicalNetworkId();
    List<ExternalLoadBalancerDeviceVO> lbDevices = null;
    String provider = _ntwkSrvcProviderDao.getProviderForServiceInNetwork(network.getId(), Service.Lb);
    assert (provider != null);
    if (dedicatedLb) {
        lbDevices = _externalLoadBalancerDeviceDao.listByProviderAndDeviceAllocationState(physicalNetworkId, provider, LBDeviceAllocationState.Free);
        if (lbDevices != null && !lbDevices.isEmpty()) {
            // return first device that is free, fully configured and meant for dedicated use
            for (ExternalLoadBalancerDeviceVO lbdevice : lbDevices) {
                if (lbdevice.getState() == LBDeviceState.Enabled && lbdevice.getIsDedicatedDevice()) {
                    return lbdevice;
                }
            }
        }
    } else {
        // get the LB devices that are already allocated for shared use
        lbDevices = _externalLoadBalancerDeviceDao.listByProviderAndDeviceAllocationState(physicalNetworkId, provider, LBDeviceAllocationState.Shared);
        if (lbDevices != null) {
            ExternalLoadBalancerDeviceVO maxFreeCapacityLbdevice = null;
            long maxFreeCapacity = 0;
            // loop through the LB device in the physical network and pick the one with maximum free capacity
            for (ExternalLoadBalancerDeviceVO lbdevice : lbDevices) {
                // skip if device is not enabled
                if (lbdevice.getState() != LBDeviceState.Enabled) {
                    continue;
                }
                // get the used capacity from the list of guest networks that are mapped to this load balancer
                List<NetworkExternalLoadBalancerVO> mappedNetworks = _networkExternalLBDao.listByLoadBalancerDeviceId(lbdevice.getId());
                long usedCapacity = ((mappedNetworks == null) || (mappedNetworks.isEmpty())) ? 0 : mappedNetworks.size();
                // get the configured capacity for this device
                long fullCapacity = lbdevice.getCapacity();
                if (fullCapacity == 0) {
                    // if capacity not configured then use the default
                    fullCapacity = _defaultLbCapacity;
                }
                long freeCapacity = fullCapacity - usedCapacity;
                if (freeCapacity > 0) {
                    if (maxFreeCapacityLbdevice == null) {
                        maxFreeCapacityLbdevice = lbdevice;
                        maxFreeCapacity = freeCapacity;
                    } else if (freeCapacity > maxFreeCapacity) {
                        maxFreeCapacityLbdevice = lbdevice;
                        maxFreeCapacity = freeCapacity;
                    }
                }
            }
            // return the device with maximum free capacity and is meant for shared use
            if (maxFreeCapacityLbdevice != null) {
                return maxFreeCapacityLbdevice;
            }
        }
        // if we are here then there are no existing LB devices in shared use or the devices in shared use has no
        // free capacity left
        // so allocate a new load balancer configured for shared use from the pool of free LB devices
        lbDevices = _externalLoadBalancerDeviceDao.listByProviderAndDeviceAllocationState(physicalNetworkId, provider, LBDeviceAllocationState.Free);
        if (lbDevices != null && !lbDevices.isEmpty()) {
            for (ExternalLoadBalancerDeviceVO lbdevice : lbDevices) {
                if (lbdevice.getState() == LBDeviceState.Enabled && !lbdevice.getIsDedicatedDevice()) {
                    return lbdevice;
                }
            }
        }
    }
    // there are no devices which capacity
    throw new InsufficientNetworkCapacityException("Unable to find a load balancing provider with sufficient capcity " + " to implement the network", Network.class, network.getId());
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InsufficientNetworkCapacityException(com.cloud.exception.InsufficientNetworkCapacityException) NetworkExternalLoadBalancerVO(com.cloud.network.dao.NetworkExternalLoadBalancerVO)

Example 8 with NetworkExternalLoadBalancerVO

use of com.cloud.network.dao.NetworkExternalLoadBalancerVO in project cloudstack by apache.

the class ExternalLoadBalancerDeviceManagerImpl method setExternalLoadBalancerForNetwork.

public void setExternalLoadBalancerForNetwork(Network network, long externalLBDeviceID) {
    NetworkExternalLoadBalancerVO lbDeviceForNetwork = new NetworkExternalLoadBalancerVO(network.getId(), externalLBDeviceID);
    _networkExternalLBDao.persist(lbDeviceForNetwork);
}
Also used : NetworkExternalLoadBalancerVO(com.cloud.network.dao.NetworkExternalLoadBalancerVO)

Example 9 with NetworkExternalLoadBalancerVO

use of com.cloud.network.dao.NetworkExternalLoadBalancerVO in project cloudstack by apache.

the class F5ExternalLoadBalancerElement method listNetworks.

@Override
public List<? extends Network> listNetworks(ListF5LoadBalancerNetworksCmd cmd) {
    Long lbDeviceId = cmd.getLoadBalancerDeviceId();
    List<NetworkVO> networks = new ArrayList<NetworkVO>();
    ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
    if (lbDeviceVo == null || !lbDeviceVo.getDeviceName().equalsIgnoreCase(NetworkDevice.F5BigIpLoadBalancer.getName())) {
        throw new InvalidParameterValueException("Could not find F5 load balancer device with ID " + lbDeviceId);
    }
    List<NetworkExternalLoadBalancerVO> networkLbMaps = _networkLBDao.listByLoadBalancerDeviceId(lbDeviceId);
    if (networkLbMaps != null && !networkLbMaps.isEmpty()) {
        for (NetworkExternalLoadBalancerVO networkLbMap : networkLbMaps) {
            NetworkVO network = _networkDao.findById(networkLbMap.getNetworkId());
            networks.add(network);
        }
    }
    return networks;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ArrayList(java.util.ArrayList) NetworkExternalLoadBalancerVO(com.cloud.network.dao.NetworkExternalLoadBalancerVO)

Example 10 with NetworkExternalLoadBalancerVO

use of com.cloud.network.dao.NetworkExternalLoadBalancerVO in project cloudstack by apache.

the class F5ExternalLoadBalancerElement method configureF5LoadBalancer.

@Override
public ExternalLoadBalancerDeviceVO configureF5LoadBalancer(ConfigureF5LoadBalancerCmd cmd) {
    Long lbDeviceId = cmd.getLoadBalancerDeviceId();
    Long capacity = cmd.getLoadBalancerCapacity();
    ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
    if ((lbDeviceVo == null) || !lbDeviceVo.getDeviceName().equalsIgnoreCase(NetworkDevice.F5BigIpLoadBalancer.getName())) {
        throw new InvalidParameterValueException("No F5 load balancer device found with ID: " + lbDeviceId);
    }
    if (capacity != null) {
        // check if any networks are using this F5 device
        List<NetworkExternalLoadBalancerVO> networks = _networkLBDao.listByLoadBalancerDeviceId(lbDeviceId);
        if ((networks != null) && !networks.isEmpty()) {
            if (capacity < networks.size()) {
                throw new CloudRuntimeException("There are more number of networks already using this F5 device than configured capacity");
            }
        }
        if (capacity != null) {
            lbDeviceVo.setCapacity(capacity);
        }
    }
    lbDeviceVo.setState(LBDeviceState.Enabled);
    _lbDeviceDao.update(lbDeviceId, lbDeviceVo);
    return lbDeviceVo;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NetworkExternalLoadBalancerVO(com.cloud.network.dao.NetworkExternalLoadBalancerVO)

Aggregations

NetworkExternalLoadBalancerVO (com.cloud.network.dao.NetworkExternalLoadBalancerVO)12 ExternalLoadBalancerDeviceVO (com.cloud.network.dao.ExternalLoadBalancerDeviceVO)11 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 InsufficientNetworkCapacityException (com.cloud.exception.InsufficientNetworkCapacityException)4 ArrayList (java.util.ArrayList)4 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)3 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)3 HostVO (com.cloud.host.HostVO)3 UnableDeleteHostException (com.cloud.resource.UnableDeleteHostException)3 DB (com.cloud.utils.db.DB)3 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)3 TransactionStatus (com.cloud.utils.db.TransactionStatus)3 URISyntaxException (java.net.URISyntaxException)3 ConfigurationException (javax.naming.ConfigurationException)3 DestroyLoadBalancerApplianceCommand (com.cloud.agent.api.routing.DestroyLoadBalancerApplianceCommand)2 DetailVO (com.cloud.host.DetailVO)2 NetworkVO (com.cloud.network.dao.NetworkVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 DestroyLoadBalancerApplianceAnswer (com.cloud.network.resource.DestroyLoadBalancerApplianceAnswer)2