Search in sources :

Example 1 with NetScalerPodVO

use of com.cloud.network.NetScalerPodVO 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());
    try {
        _agentMgr.reconnect(host.getId());
    } catch (AgentUnavailableException e) {
        s_logger.warn("failed to reconnect host " + host, e);
    }
    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) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DB(com.cloud.utils.db.DB)

Example 2 with NetScalerPodVO

use of com.cloud.network.NetScalerPodVO in project cloudstack by apache.

the class NetscalerElement method createNetscalerLoadBalancerResponse.

@Override
public NetscalerLoadBalancerResponse createNetscalerLoadBalancerResponse(ExternalLoadBalancerDeviceVO lbDeviceVO) {
    NetscalerLoadBalancerResponse response = new NetscalerLoadBalancerResponse();
    Host lbHost = _hostDao.findById(lbDeviceVO.getHostId());
    Map<String, String> lbDetails = _detailsDao.findDetails(lbDeviceVO.getHostId());
    response.setId(lbDeviceVO.getUuid());
    response.setIpAddress(lbHost.getPrivateIpAddress());
    PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(lbDeviceVO.getPhysicalNetworkId());
    if (pnw != null) {
        response.setPhysicalNetworkId(pnw.getUuid());
    }
    response.setPublicInterface(lbDetails.get("publicInterface"));
    response.setPrivateInterface(lbDetails.get("privateInterface"));
    response.setDeviceName(lbDeviceVO.getDeviceName());
    if (lbDeviceVO.getCapacity() == 0) {
        long defaultLbCapacity = NumbersUtil.parseLong(_configDao.getValue(Config.DefaultExternalLoadBalancerCapacity.key()), 50);
        response.setDeviceCapacity(defaultLbCapacity);
    } else {
        response.setDeviceCapacity(lbDeviceVO.getCapacity());
    }
    response.setDedicatedLoadBalancer(lbDeviceVO.getIsDedicatedDevice());
    response.setProvider(lbDeviceVO.getProviderName());
    response.setDeviceState(lbDeviceVO.getState().name());
    response.setObjectName("netscalerloadbalancer");
    response.setGslbProvider(lbDeviceVO.getGslbProvider());
    response.setExclusiveGslbProvider(lbDeviceVO.getExclusiveGslbProvider());
    response.setGslbSitePublicIp(lbDeviceVO.getGslbSitePublicIP());
    response.setGslbSitePrivateIp(lbDeviceVO.getGslbSitePrivateIP());
    List<Long> associatedPods = new ArrayList<Long>();
    List<NetScalerPodVO> currentPodVOs = _netscalerPodDao.listByNetScalerDeviceId(lbDeviceVO.getId());
    if (currentPodVOs != null && currentPodVOs.size() > 0) {
        for (NetScalerPodVO nsPodVo : currentPodVOs) {
            associatedPods.add(nsPodVo.getPodId());
        }
    }
    response.setAssociatedPods(associatedPods);
    return response;
}
Also used : PhysicalNetwork(com.cloud.network.PhysicalNetwork) NetscalerLoadBalancerResponse(com.cloud.api.response.NetscalerLoadBalancerResponse) ArrayList(java.util.ArrayList) Host(com.cloud.host.Host) NetScalerPodVO(com.cloud.network.NetScalerPodVO)

Example 3 with NetScalerPodVO

use of com.cloud.network.NetScalerPodVO in project cloudstack by apache.

the class NetscalerElement method getNetScalerForEIP.

// returns configured NetScaler device that is associated with the pod that
// owns guest IP
private ExternalLoadBalancerDeviceVO getNetScalerForEIP(StaticNat rule) {
    String guestIP = rule.getDestIpAddress();
    List<DataCenterIpAddressVO> dcGuestIps = _privateIpAddressDao.listAll();
    if (dcGuestIps != null) {
        for (DataCenterIpAddressVO dcGuestIp : dcGuestIps) {
            if (dcGuestIp.getIpAddress().equalsIgnoreCase(guestIP)) {
                long podId = dcGuestIp.getPodId();
                NetScalerPodVO nsPodVO = _netscalerPodDao.findByPodId(podId);
                if (nsPodVO != null) {
                    ExternalLoadBalancerDeviceVO lbDeviceVO = _lbDeviceDao.findById(nsPodVO.getNetscalerDeviceId());
                    return lbDeviceVO;
                }
            }
        }
    }
    return null;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) DataCenterIpAddressVO(com.cloud.dc.DataCenterIpAddressVO) NetScalerPodVO(com.cloud.network.NetScalerPodVO)

Aggregations

NetScalerPodVO (com.cloud.network.NetScalerPodVO)3 ExternalLoadBalancerDeviceVO (com.cloud.network.dao.ExternalLoadBalancerDeviceVO)2 ArrayList (java.util.ArrayList)2 NetscalerLoadBalancerResponse (com.cloud.api.response.NetscalerLoadBalancerResponse)1 DataCenterIpAddressVO (com.cloud.dc.DataCenterIpAddressVO)1 HostPodVO (com.cloud.dc.HostPodVO)1 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)1 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)1 Host (com.cloud.host.Host)1 HostVO (com.cloud.host.HostVO)1 PhysicalNetwork (com.cloud.network.PhysicalNetwork)1 NetworkExternalLoadBalancerVO (com.cloud.network.dao.NetworkExternalLoadBalancerVO)1 DB (com.cloud.utils.db.DB)1 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)1 TransactionStatus (com.cloud.utils.db.TransactionStatus)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1