Search in sources :

Example 11 with ExternalLoadBalancerDeviceVO

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

the class F5ExternalLoadBalancerElement method deleteF5LoadBalancer.

@Override
public boolean deleteF5LoadBalancer(DeleteF5LoadBalancerCmd cmd) {
    Long lbDeviceId = cmd.getLoadBalancerDeviceId();
    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);
    }
    return deleteExternalLoadBalancer(lbDeviceVo.getHostId());
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException)

Example 12 with ExternalLoadBalancerDeviceVO

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

the class F5ExternalLoadBalancerElement method getIpDeployer.

@Override
public IpDeployer getIpDeployer(Network network) {
    ExternalLoadBalancerDeviceVO lbDevice = getExternalLoadBalancerForNetwork(network);
    if (lbDevice == null) {
        s_logger.error("Cannot find external load balanacer for network " + network.getName());
        s_logger.error("Make F5 as dummy ip deployer, since we likely met this when clean up resource after shutdown network");
        return this;
    }
    if (_networkManager.isNetworkInlineMode(network)) {
        return getIpDeployerForInlineMode(network);
    }
    return this;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO)

Example 13 with ExternalLoadBalancerDeviceVO

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

the class ConfigureF5LoadBalancerCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
    try {
        ExternalLoadBalancerDeviceVO lbDeviceVO = _f5DeviceManagerService.configureF5LoadBalancer(this);
        if (lbDeviceVO != null) {
            F5LoadBalancerResponse response = _f5DeviceManagerService.createF5LoadBalancerResponse(lbDeviceVO);
            response.setObjectName("f5loadbalancer");
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure F5 load balancer due to internal error.");
        }
    } catch (InvalidParameterValueException invalidParamExcp) {
        throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
    } catch (CloudRuntimeException runtimeExcp) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
    }
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) F5LoadBalancerResponse(com.cloud.api.response.F5LoadBalancerResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 14 with ExternalLoadBalancerDeviceVO

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

the class ExternalLoadBalancerDeviceManagerImpl method listExternalLoadBalancers.

@Override
public List<Host> listExternalLoadBalancers(long physicalNetworkId, String deviceName) {
    List<Host> lbHosts = new ArrayList<Host>();
    NetworkDevice lbNetworkDevice = NetworkDevice.getNetworkDevice(deviceName);
    PhysicalNetworkVO pNetwork = null;
    pNetwork = _physicalNetworkDao.findById(physicalNetworkId);
    if ((pNetwork == null) || (lbNetworkDevice == null)) {
        throw new InvalidParameterValueException("Atleast one of the required parameter physical networkId, device name is invalid.");
    }
    PhysicalNetworkServiceProviderVO ntwkSvcProvider = _physicalNetworkServiceProviderDao.findByServiceProvider(pNetwork.getId(), lbNetworkDevice.getNetworkServiceProvder());
    // if provider not configured in to physical network, then there can be no instances
    if (ntwkSvcProvider == null) {
        return null;
    }
    List<ExternalLoadBalancerDeviceVO> lbDevices = _externalLoadBalancerDeviceDao.listByPhysicalNetworkAndProvider(physicalNetworkId, ntwkSvcProvider.getProviderName());
    for (ExternalLoadBalancerDeviceVO provderInstance : lbDevices) {
        lbHosts.add(_hostDao.findById(provderInstance.getHostId()));
    }
    return lbHosts;
}
Also used : ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) PhysicalNetworkServiceProviderVO(com.cloud.network.dao.PhysicalNetworkServiceProviderVO) NetworkDevice(org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice) ArrayList(java.util.ArrayList) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Host(com.cloud.host.Host)

Example 15 with ExternalLoadBalancerDeviceVO

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

the class ExternalLoadBalancerDeviceManagerImpl method applyLoadBalancerRules.

@Override
public boolean applyLoadBalancerRules(Network network, List<LoadBalancingRule> loadBalancingRules) throws ResourceUnavailableException {
    // Find the external load balancer in this zone
    long zoneId = network.getDataCenterId();
    DataCenterVO zone = _dcDao.findById(zoneId);
    if (loadBalancingRules == null || loadBalancingRules.isEmpty()) {
        return true;
    }
    HostVO externalLoadBalancer = null;
    if (isNccServiceProvider(network)) {
        externalLoadBalancer = getNetScalerControlCenterForNetwork(network);
    } else {
        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 true;
        } else {
            externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId());
        }
    }
    boolean externalLoadBalancerIsInline = _networkMgr.isNetworkInlineMode(network);
    if (network.getState() == Network.State.Allocated) {
        s_logger.debug("External load balancer was asked to apply LB rules for network with ID " + network.getId() + "; this network is not implemented. Skipping backend commands.");
        return true;
    }
    List<LoadBalancerTO> loadBalancersToApply = new ArrayList<LoadBalancerTO>();
    List<MappingState> mappingStates = new ArrayList<MappingState>();
    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 uuid = rule.getUuid();
        String srcIp = rule.getSourceIp().addr();
        String srcIpVlan = null;
        String srcIpGateway = null;
        String srcIpNetmask = null;
        Long vlanid = _networkModel.getPublicIpAddress(rule.getSourceIp().addr(), network.getDataCenterId()).getVlanId();
        if (vlanid != null) {
            VlanVO publicVlan = _vlanDao.findById(vlanid);
            srcIpVlan = publicVlan.getVlanTag();
            srcIpGateway = publicVlan.getVlanGateway();
            srcIpNetmask = publicVlan.getVlanNetmask();
        }
        int srcPort = rule.getSourcePortStart();
        List<LbDestination> destinations = rule.getDestinations();
        if (externalLoadBalancerIsInline) {
            long ipId = _networkModel.getPublicIpAddress(rule.getSourceIp().addr(), network.getDataCenterId()).getId();
            MappingNic nic = getLoadBalancingIpNic(zone, network, ipId, revoked, null);
            mappingStates.add(nic.getState());
            Nic loadBalancingIpNic = nic.getNic();
            if (loadBalancingIpNic == null) {
                continue;
            }
            // Change the source IP address for the load balancing rule to be the load balancing IP address
            srcIp = loadBalancingIpNic.getIPv4Address();
        }
        if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) {
            boolean inline = _networkMgr.isNetworkInlineMode(network);
            LoadBalancerTO loadBalancer = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, rule.getStickinessPolicies(), rule.getHealthCheckPolicies(), rule.getLbSslCert(), rule.getLbProtocol());
            loadBalancer.setNetworkId(network.getId());
            loadBalancer.setSrcIpVlan(srcIpVlan);
            loadBalancer.setSrcIpNetmask(srcIpNetmask);
            loadBalancer.setSrcIpGateway(srcIpGateway);
            if (rule.isAutoScaleConfig()) {
                loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
            }
            loadBalancersToApply.add(loadBalancer);
        }
    }
    try {
        if (loadBalancersToApply.size() > 0) {
            int numLoadBalancersForCommand = loadBalancersToApply.size();
            LoadBalancerTO[] loadBalancersForCommand = loadBalancersToApply.toArray(new LoadBalancerTO[numLoadBalancersForCommand]);
            LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(loadBalancersForCommand, null);
            long guestVlanTag = Integer.parseInt(BroadcastDomainType.getValue(network.getBroadcastUri()));
            cmd.setAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG, String.valueOf(guestVlanTag));
            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 load balancer rules to the external load balancer appliance in zone " + zone.getName() + " due to: " + details + ".";
                s_logger.error(msg);
                throw new ResourceUnavailableException(msg, DataCenter.class, network.getDataCenterId());
            }
        }
    } catch (Exception ex) {
        if (externalLoadBalancerIsInline) {
            s_logger.error("Rollbacking static nat operation of inline mode load balancing due to error on applying LB rules!");
            String existedGuestIp = loadBalancersToApply.get(0).getSrcIp();
            // Rollback static NAT operation in current session
            for (int i = 0; i < loadBalancingRules.size(); i++) {
                LoadBalancingRule rule = loadBalancingRules.get(i);
                MappingState state = mappingStates.get(i);
                boolean revoke;
                if (state == MappingState.Create) {
                    revoke = true;
                } else if (state == MappingState.Remove) {
                    revoke = false;
                } else {
                    continue;
                }
                long sourceIpId = _networkModel.getPublicIpAddress(rule.getSourceIp().addr(), network.getDataCenterId()).getId();
                getLoadBalancingIpNic(zone, network, sourceIpId, revoke, existedGuestIp);
            }
        }
        throw new ResourceUnavailableException(ex.getMessage(), 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) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) VlanVO(com.cloud.dc.VlanVO) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand) DataCenterVO(com.cloud.dc.DataCenterVO) Nic(com.cloud.vm.Nic) HostVO(com.cloud.host.HostVO) TransactionCallbackWithException(com.cloud.utils.db.TransactionCallbackWithException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InsufficientNetworkCapacityException(com.cloud.exception.InsufficientNetworkCapacityException) URISyntaxException(java.net.URISyntaxException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConfigurationException(javax.naming.ConfigurationException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException) DestroyLoadBalancerApplianceAnswer(com.cloud.network.resource.DestroyLoadBalancerApplianceAnswer) Answer(com.cloud.agent.api.Answer) CreateLoadBalancerApplianceAnswer(com.cloud.network.resource.CreateLoadBalancerApplianceAnswer) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer) DataCenter(com.cloud.dc.DataCenter) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

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