Search in sources :

Example 21 with ExternalLoadBalancerDeviceVO

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

the class F5ExternalLoadBalancerElement method addExternalLoadBalancer.

@Override
@Deprecated
public Host addExternalLoadBalancer(AddExternalLoadBalancerCmd cmd) {
    Long zoneId = cmd.getZoneId();
    DataCenterVO zone = null;
    PhysicalNetworkVO pNetwork = null;
    ExternalLoadBalancerDeviceVO lbDeviceVO = null;
    HostVO lbHost = null;
    zone = _dcDao.findById(zoneId);
    if (zone == null) {
        throw new InvalidParameterValueException("Could not find zone with ID: " + zoneId);
    }
    List<PhysicalNetworkVO> physicalNetworks = _physicalNetworkDao.listByZone(zoneId);
    if ((physicalNetworks == null) || (physicalNetworks.size() > 1)) {
        throw new InvalidParameterValueException("There are no physical networks or multiple physical networks configured in zone with ID: " + zoneId + " to add this device.");
    }
    pNetwork = physicalNetworks.get(0);
    String deviceType = NetworkDevice.F5BigIpLoadBalancer.getName();
    lbDeviceVO = addExternalLoadBalancer(pNetwork.getId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceType, new F5BigIpResource(), false, false, null, null);
    if (lbDeviceVO != null) {
        lbHost = _hostDao.findById(lbDeviceVO.getHostId());
    }
    return lbHost;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) F5BigIpResource(com.cloud.network.resource.F5BigIpResource) HostVO(com.cloud.host.HostVO)

Example 22 with ExternalLoadBalancerDeviceVO

use of com.cloud.network.dao.ExternalLoadBalancerDeviceVO 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)

Example 23 with ExternalLoadBalancerDeviceVO

use of com.cloud.network.dao.ExternalLoadBalancerDeviceVO 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 24 with ExternalLoadBalancerDeviceVO

use of com.cloud.network.dao.ExternalLoadBalancerDeviceVO 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, network.getId());
        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 25 with ExternalLoadBalancerDeviceVO

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

the class NetscalerElement method findGslbProvider.

private ExternalLoadBalancerDeviceVO findGslbProvider(long zoneId, long physicalNetworkId) {
    List<PhysicalNetworkVO> pNtwks = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, TrafficType.Guest);
    if (pNtwks == null || pNtwks.isEmpty()) {
        throw new InvalidParameterValueException("Unable to get physical network: " + physicalNetworkId + " in zone id = " + zoneId);
    } else {
        for (PhysicalNetwork physicalNetwork : pNtwks) {
            if (physicalNetwork.getId() == physicalNetworkId) {
                PhysicalNetworkVO physNetwork = pNtwks.get(0);
                ExternalLoadBalancerDeviceVO nsGslbProvider = _externalLoadBalancerDeviceDao.findGslbServiceProvider(physNetwork.getId(), Provider.Netscaler.getName());
                return nsGslbProvider;
            }
        }
    }
    return null;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetwork(com.cloud.network.PhysicalNetwork) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO)

Aggregations

ExternalLoadBalancerDeviceVO (com.cloud.network.dao.ExternalLoadBalancerDeviceVO)36 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)26 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 ArrayList (java.util.ArrayList)14 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)12 NetworkExternalLoadBalancerVO (com.cloud.network.dao.NetworkExternalLoadBalancerVO)12 InsufficientNetworkCapacityException (com.cloud.exception.InsufficientNetworkCapacityException)11 HostVO (com.cloud.host.HostVO)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9 ConfigurationException (javax.naming.ConfigurationException)9 ServerApiException (org.apache.cloudstack.api.ServerApiException)9 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)8 HealthCheckLBConfigAnswer (com.cloud.agent.api.routing.HealthCheckLBConfigAnswer)6 DataCenterVO (com.cloud.dc.DataCenterVO)5 UnableDeleteHostException (com.cloud.resource.UnableDeleteHostException)5 TransactionCallbackWithException (com.cloud.utils.db.TransactionCallbackWithException)5 URISyntaxException (java.net.URISyntaxException)5 Answer (com.cloud.agent.api.Answer)4 LoadBalancerTO (com.cloud.agent.api.to.LoadBalancerTO)4 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)4