Search in sources :

Example 11 with NetworkExternalLoadBalancerVO

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

the class NetscalerElement method configureNetscalerLoadBalancer.

@DB
private ExternalLoadBalancerDeviceVO configureNetscalerLoadBalancer(final long lbDeviceId, Long capacity, Boolean dedicatedUse, List<Long> newPodsConfig) {
    final ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
    final Map<String, String> lbDetails = _detailsDao.findDetails(lbDeviceVo.getHostId());
    if ((lbDeviceVo == null) || !isNetscalerDevice(lbDeviceVo.getDeviceName())) {
        throw new InvalidParameterValueException("No netscaler device found with ID: " + lbDeviceId);
    }
    List<Long> currentPodsConfig = new ArrayList<Long>();
    List<NetScalerPodVO> currentPodVOs = _netscalerPodDao.listByNetScalerDeviceId(lbDeviceVo.getId());
    if (currentPodVOs != null && currentPodVOs.size() > 0) {
        for (NetScalerPodVO nsPodVo : currentPodVOs) {
            currentPodsConfig.add(nsPodVo.getPodId());
        }
    }
    final List<Long> podsToAssociate = new ArrayList<Long>();
    if (newPodsConfig != null && newPodsConfig.size() > 0) {
        for (Long podId : newPodsConfig) {
            HostPodVO pod = _podDao.findById(podId);
            if (pod == null) {
                throw new InvalidParameterValueException("Can't find pod by id " + podId);
            }
        }
        for (Long podId : newPodsConfig) {
            if (!currentPodsConfig.contains(podId)) {
                podsToAssociate.add(podId);
            }
        }
    }
    final List<Long> podsToDeassociate = new ArrayList<Long>();
    for (Long podId : currentPodsConfig) {
        if (!newPodsConfig.contains(podId)) {
            podsToDeassociate.add(podId);
        }
    }
    String deviceName = lbDeviceVo.getDeviceName();
    if (dedicatedUse != null || capacity != null) {
        if (NetworkDevice.NetscalerSDXLoadBalancer.getName().equalsIgnoreCase(deviceName) || NetworkDevice.NetscalerMPXLoadBalancer.getName().equalsIgnoreCase(deviceName)) {
            if (dedicatedUse != null && dedicatedUse == true) {
                throw new InvalidParameterValueException("Netscaler MPX and SDX device should be shared and can not be dedicated to a single account.");
            }
        }
        // check if any networks are using this netscaler device
        List<NetworkExternalLoadBalancerVO> networks = _networkLBDao.listByLoadBalancerDeviceId(lbDeviceId);
        if ((networks != null) && !networks.isEmpty()) {
            if (capacity != null && capacity < networks.size()) {
                throw new CloudRuntimeException("There are more number of networks already using this netscaler device than configured capacity");
            }
            if (dedicatedUse != null && dedicatedUse == true) {
                throw new CloudRuntimeException("There are networks already using this netscaler device to make device dedicated");
            }
        }
    }
    if (!NetworkDevice.NetscalerSDXLoadBalancer.getName().equalsIgnoreCase(deviceName)) {
        if (capacity != null) {
            lbDeviceVo.setCapacity(capacity);
        }
    } else {
    // FIXME how to interpret configured capacity of the SDX device
    }
    if (dedicatedUse != null) {
        lbDeviceVo.setIsDedicatedDevice(dedicatedUse);
    }
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(TransactionStatus status) {
            _lbDeviceDao.update(lbDeviceId, lbDeviceVo);
            for (Long podId : podsToAssociate) {
                NetScalerPodVO nsPodVo = new NetScalerPodVO(lbDeviceId, podId);
                _netscalerPodDao.persist(nsPodVo);
            }
            for (Long podId : podsToDeassociate) {
                NetScalerPodVO nsPodVo = _netscalerPodDao.findByPodId(podId);
                _netscalerPodDao.remove(nsPodVo.getId());
            }
            // FIXME get the row lock to avoid race condition
            _detailsDao.persist(lbDeviceVo.getHostId(), lbDetails);
        }
    });
    HostVO host = _hostDao.findById(lbDeviceVo.getHostId());
    _agentMgr.reconnect(host.getId());
    return lbDeviceVo;
}
Also used : ArrayList(java.util.ArrayList) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) NetworkExternalLoadBalancerVO(com.cloud.network.dao.NetworkExternalLoadBalancerVO) HostPodVO(com.cloud.dc.HostPodVO) HostVO(com.cloud.host.HostVO) NetScalerPodVO(com.cloud.network.NetScalerPodVO) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DB(com.cloud.utils.db.DB)

Example 12 with NetworkExternalLoadBalancerVO

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

the class ExternalLoadBalancerDeviceManagerImplTest method setupLBHealthChecksMocks.

private void setupLBHealthChecksMocks() throws URISyntaxException {
    Mockito.when(network.getId()).thenReturn(42l);
    Mockito.when(network.getBroadcastUri()).thenReturn(new URI("vlan://1"));
    NetworkExternalLoadBalancerVO externalLb = Mockito.mock(NetworkExternalLoadBalancerVO.class);
    Mockito.when(externalLb.getExternalLBDeviceId()).thenReturn(66l);
    Mockito.when(_networkExternalLBDao.findByNetworkId(42)).thenReturn(externalLb);
    ExternalLoadBalancerDeviceVO lbDevice = Mockito.mock(ExternalLoadBalancerDeviceVO.class);
    Mockito.when(_externalLoadBalancerDeviceDao.findById(66l)).thenReturn(lbDevice);
    Mockito.when(rule.getAlgorithm()).thenReturn("TEST");
    Mockito.when(rule.getProtocol()).thenReturn("TEST");
    Mockito.when(rule.getSourceIp()).thenReturn(new Ip(1l));
    Mockito.when(lbDevice.getHostId()).thenReturn(99l);
    HostVO hostVo = Mockito.mock(HostVO.class);
    Mockito.when(_hostDao.findById(Mockito.anyLong())).thenReturn(hostVo);
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) Ip(com.cloud.utils.net.Ip) NetworkExternalLoadBalancerVO(com.cloud.network.dao.NetworkExternalLoadBalancerVO) URI(java.net.URI) HostVO(com.cloud.host.HostVO)

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