Search in sources :

Example 6 with ExternalLoadBalancerDeviceVO

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

the class NetscalerElement method applyGlobalLoadBalancerRule.

@Override
public boolean applyGlobalLoadBalancerRule(long zoneId, long physicalNetworkId, GlobalLoadBalancerConfigCommand gslbConfigCmd) throws ResourceUnavailableException {
    long zoneGslbProviderHosId = 0;
    // find the NetScaler device configured as gslb service provider in the
    // zone
    ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId, physicalNetworkId);
    if (nsGslbProvider == null) {
        String msg = "Unable to find a NetScaler configured as gslb service provider in zone " + zoneId;
        s_logger.debug(msg);
        throw new ResourceUnavailableException(msg, DataCenter.class, zoneId);
    }
    // get the host Id corresponding to NetScaler acting as GSLB service
    // provider in the zone
    zoneGslbProviderHosId = nsGslbProvider.getHostId();
    // send gslb configuration to NetScaler device
    Answer answer = _agentMgr.easySend(zoneGslbProviderHosId, gslbConfigCmd);
    if (answer == null || !answer.getResult()) {
        String msg = "Unable to apply global load balancer rule to the gslb service provider in zone " + zoneId;
        s_logger.debug(msg);
        throw new ResourceUnavailableException(msg, DataCenter.class, zoneId);
    }
    return true;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) Answer(com.cloud.agent.api.Answer) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 7 with ExternalLoadBalancerDeviceVO

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

the class NetscalerElement method applyElasticLoadBalancerRules.

public boolean applyElasticLoadBalancerRules(Network network, List<LoadBalancingRule> loadBalancingRules) throws ResourceUnavailableException {
    if (loadBalancingRules == null || loadBalancingRules.isEmpty()) {
        return true;
    }
    String errMsg = null;
    ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(network);
    if (lbDeviceVO == null) {
        try {
            lbDeviceVO = allocateLoadBalancerForNetwork(network);
        } catch (Exception e) {
            errMsg = "Could not allocate a NetSclaer load balancer for configuring elastic load balancer rules due to " + e.getMessage();
            s_logger.error(errMsg);
            throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
        }
    }
    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, rule.getStickinessPolicies(), rule.getHealthCheckPolicies(), rule.getLbSslCert(), rule.getLbProtocol());
            if (rule.isAutoScaleConfig()) {
                loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
            }
            loadBalancersToApply.add(loadBalancer);
        }
    }
    if (loadBalancersToApply.size() > 0) {
        int numLoadBalancersForCommand = loadBalancersToApply.size();
        LoadBalancerTO[] loadBalancersForCommand = loadBalancersToApply.toArray(new LoadBalancerTO[numLoadBalancersForCommand]);
        LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(loadBalancersForCommand, null);
        HostVO externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId());
        Answer answer = _agentMgr.easySend(externalLoadBalancer.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            String details = (answer != null) ? answer.getDetails() : "details unavailable";
            String msg = "Unable to apply elastic load balancer rules to the external load balancer appliance in zone " + network.getDataCenterId() + " due to: " + details + ".";
            s_logger.error(msg);
            throw new ResourceUnavailableException(msg, DataCenter.class, network.getDataCenterId());
        }
    }
    return true;
}
Also used : LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) JSONException(org.json.JSONException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InsufficientNetworkCapacityException(com.cloud.exception.InsufficientNetworkCapacityException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) HostVO(com.cloud.host.HostVO) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) Answer(com.cloud.agent.api.Answer) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) GlobalLoadBalancerConfigCommand(com.cloud.agent.api.routing.GlobalLoadBalancerConfigCommand) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand)

Example 8 with ExternalLoadBalancerDeviceVO

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

the class NetscalerElement method deleteNetscalerLoadBalancer.

@Override
public boolean deleteNetscalerLoadBalancer(DeleteNetscalerLoadBalancerCmd cmd) {
    Long lbDeviceId = cmd.getLoadBalancerDeviceId();
    ExternalLoadBalancerDeviceVO lbDeviceVo = _lbDeviceDao.findById(lbDeviceId);
    if ((lbDeviceVo == null) || !isNetscalerDevice(lbDeviceVo.getDeviceName())) {
        throw new InvalidParameterValueException("No netscaler device found with ID: " + lbDeviceId);
    }
    return deleteExternalLoadBalancer(lbDeviceVo.getHostId());
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Example 9 with ExternalLoadBalancerDeviceVO

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

the class NetscalerElement method applyStaticNats.

@Override
public boolean applyStaticNats(Network config, List<? extends StaticNat> rules) throws ResourceUnavailableException {
    if (!canHandle(config, Service.StaticNat)) {
        return false;
    }
    boolean multiNetScalerDeployment = Boolean.valueOf(_configDao.getValue(Config.EIPWithMultipleNetScalersEnabled.key()));
    try {
        if (!multiNetScalerDeployment) {
            String errMsg;
            ExternalLoadBalancerDeviceVO lbDevice = getExternalLoadBalancerForNetwork(config);
            if (lbDevice == null) {
                try {
                    lbDevice = allocateLoadBalancerForNetwork(config);
                } catch (Exception e) {
                    errMsg = "Could not allocate a NetSclaer load balancer for configuring static NAT rules due to" + e.getMessage();
                    s_logger.error(errMsg);
                    throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
                }
            }
            if (!isNetscalerDevice(lbDevice.getDeviceName())) {
                errMsg = "There are no NetScaler load balancer assigned for this network. So NetScaler element will not be handling the static nat rules.";
                s_logger.error(errMsg);
                throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
            }
            SetStaticNatRulesAnswer answer = null;
            List<StaticNatRuleTO> rulesTO = null;
            if (rules != null) {
                rulesTO = new ArrayList<StaticNatRuleTO>();
                for (StaticNat rule : rules) {
                    IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId());
                    StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
                    rulesTO.add(ruleTO);
                }
            }
            SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, null);
            answer = (SetStaticNatRulesAnswer) _agentMgr.send(lbDevice.getHostId(), cmd);
            if (answer == null) {
                return false;
            } else {
                return answer.getResult();
            }
        } else {
            if (rules != null) {
                for (StaticNat rule : rules) {
                    // validate if EIP rule can be configured.
                    ExternalLoadBalancerDeviceVO lbDevice = getNetScalerForEIP(rule);
                    if (lbDevice == null) {
                        String errMsg = "There is no NetScaler device configured to perform EIP to guest IP address: " + rule.getDestIpAddress();
                        s_logger.error(errMsg);
                        throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
                    }
                    List<StaticNatRuleTO> rulesTO = new ArrayList<StaticNatRuleTO>();
                    IpAddress sourceIp = _networkMgr.getIp(rule.getSourceIpAddressId());
                    StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
                    rulesTO.add(ruleTO);
                    SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, null);
                    // send commands to configure INAT rule on the NetScaler
                    // device
                    SetStaticNatRulesAnswer answer = (SetStaticNatRulesAnswer) _agentMgr.send(lbDevice.getHostId(), cmd);
                    if (answer == null) {
                        String errMsg = "Failed to configure INAT rule on NetScaler device " + lbDevice.getHostId();
                        s_logger.error(errMsg);
                        throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
                    }
                }
                return true;
            }
        }
        return true;
    } catch (Exception e) {
        s_logger.error("Failed to configure StaticNat rule due to " + e.getMessage());
        return false;
    }
}
Also used : StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) ArrayList(java.util.ArrayList) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) JSONException(org.json.JSONException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InsufficientNetworkCapacityException(com.cloud.exception.InsufficientNetworkCapacityException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) StaticNat(com.cloud.network.rules.StaticNat) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer)

Example 10 with ExternalLoadBalancerDeviceVO

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

the class F5ExternalLoadBalancerElement method listF5LoadBalancers.

@Override
public List<ExternalLoadBalancerDeviceVO> listF5LoadBalancers(ListF5LoadBalancersCmd cmd) {
    Long physcialNetworkId = cmd.getPhysicalNetworkId();
    Long lbDeviceId = cmd.getLoadBalancerDeviceId();
    PhysicalNetworkVO pNetwork = null;
    List<ExternalLoadBalancerDeviceVO> lbDevices = new ArrayList<ExternalLoadBalancerDeviceVO>();
    if (physcialNetworkId == null && lbDeviceId == null) {
        throw new InvalidParameterValueException("Either physical network Id or load balancer device Id must be specified");
    }
    if (lbDeviceId != null) {
        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);
        }
        lbDevices.add(lbDeviceVo);
        return lbDevices;
    }
    if (physcialNetworkId != null) {
        pNetwork = _physicalNetworkDao.findById(physcialNetworkId);
        if (pNetwork == null) {
            throw new InvalidParameterValueException("Could not find phyical network with ID: " + physcialNetworkId);
        }
        lbDevices = _lbDeviceDao.listByPhysicalNetworkAndProvider(physcialNetworkId, Provider.F5BigIp.getName());
        return lbDevices;
    }
    return null;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList)

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