Search in sources :

Example 1 with ElasticLbVmMapVO

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

the class ElasticLoadBalancerManagerImpl method findElbVmForLb.

protected DomainRouterVO findElbVmForLb(LoadBalancingRule lb) {
    //TODO: use a table to lookup
    Network ntwk = _networkModel.getNetwork(lb.getNetworkId());
    long sourceIpId = _networkModel.getPublicIpAddress(lb.getSourceIp().addr(), ntwk.getDataCenterId()).getId();
    ElasticLbVmMapVO map = _elbVmMapDao.findOneByIp(sourceIpId);
    if (map == null) {
        return null;
    }
    DomainRouterVO elbVm = _routerDao.findById(map.getElbVmId());
    return elbVm;
}
Also used : ElasticLbVmMapVO(com.cloud.network.ElasticLbVmMapVO) Network(com.cloud.network.Network) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 2 with ElasticLbVmMapVO

use of com.cloud.network.ElasticLbVmMapVO in project CloudStack-archive by CloudStack-extras.

the class ElbVmMapDaoTest method testFindByIp.

public void testFindByIp() {
    ElasticLbVmMapDaoImpl dao = ComponentLocator.inject(ElasticLbVmMapDaoImpl.class);
    ElasticLbVmMapVO map = dao.findOneByIp(3);
    if (map == null) {
        System.out.println("Not Found");
    } else {
        System.out.println("Found");
    }
}
Also used : ElasticLbVmMapVO(com.cloud.network.ElasticLbVmMapVO) ElasticLbVmMapDaoImpl(com.cloud.network.lb.dao.ElasticLbVmMapDaoImpl)

Example 3 with ElasticLbVmMapVO

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

the class LoadBalanceRuleHandler method handleCreateLoadBalancerRuleWithLock.

private LoadBalancer handleCreateLoadBalancerRuleWithLock(final CreateLoadBalancerRuleCmd lb, final Account account, final long networkId) throws InsufficientAddressCapacityException, NetworkRuleConflictException {
    Long ipId = null;
    boolean newIp = false;
    List<LoadBalancerVO> existingLbs = findExistingLoadBalancers(lb.getName(), lb.getSourceIpAddressId(), lb.getAccountId(), lb.getDomainId(), lb.getSourcePortStart());
    if (existingLbs == null) {
        existingLbs = findExistingLoadBalancers(lb.getName(), lb.getSourceIpAddressId(), lb.getAccountId(), lb.getDomainId(), null);
        if (existingLbs == null) {
            if (lb.getSourceIpAddressId() != null) {
                throwExceptionIfSuppliedlLbNameIsNotAssociatedWithIpAddress(lb);
            } else {
                s_logger.debug("Could not find any existing frontend ips for this account for this LB rule, acquiring a new frontent IP for ELB");
                final PublicIp ip = allocDirectIp(account, networkId);
                ipId = ip.getId();
                newIp = true;
            }
        } else {
            ipId = existingLbs.get(0).getSourceIpAddressId();
            s_logger.debug("ELB: Found existing frontend ip for this account for this LB rule " + ipId);
        }
    } else {
        s_logger.warn("ELB: Found existing load balancers matching requested new LB");
        throw new NetworkRuleConflictException("ELB: Found existing load balancers matching requested new LB");
    }
    final IPAddressVO ipAddr = _ipAddressDao.findById(ipId);
    LoadBalancer result = null;
    try {
        lb.setSourceIpAddressId(ipId);
        result = _lbMgr.createPublicLoadBalancer(lb.getXid(), lb.getName(), lb.getDescription(), lb.getSourcePortStart(), lb.getDefaultPortStart(), ipId.longValue(), lb.getProtocol(), lb.getAlgorithm(), false, CallContext.current(), lb.getLbProtocol(), true);
    } catch (final NetworkRuleConflictException e) {
        s_logger.warn("Failed to create LB rule, not continuing with ELB deployment");
        if (newIp) {
            releaseIp(ipId, CallContext.current().getCallingUserId(), account);
        }
        throw e;
    }
    DomainRouterVO elbVm = null;
    if (existingLbs == null) {
        elbVm = findElbVmWithCapacity(ipAddr);
        if (elbVm == null) {
            elbVm = deployLoadBalancerVM(networkId, ipAddr);
            if (elbVm == null) {
                final Network network = _networkModel.getNetwork(networkId);
                s_logger.warn("Failed to deploy a new ELB vm for ip " + ipAddr + " in network " + network + "lb name=" + lb.getName());
                if (newIp) {
                    releaseIp(ipId, CallContext.current().getCallingUserId(), account);
                }
            }
        }
    } else {
        final ElasticLbVmMapVO elbVmMap = _elbVmMapDao.findOneByIp(ipId);
        if (elbVmMap != null) {
            elbVm = _routerDao.findById(elbVmMap.getElbVmId());
        }
    }
    if (elbVm == null) {
        s_logger.warn("No ELB VM can be found or deployed");
        s_logger.warn("Deleting LB since we failed to deploy ELB VM");
        _lbDao.remove(result.getId());
        return null;
    }
    final ElasticLbVmMapVO mapping = new ElasticLbVmMapVO(ipId, elbVm.getId(), result.getId());
    _elbVmMapDao.persist(mapping);
    return result;
}
Also used : ElasticLbVmMapVO(com.cloud.network.ElasticLbVmMapVO) PublicIp(com.cloud.network.addr.PublicIp) Network(com.cloud.network.Network) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LoadBalancer(com.cloud.network.rules.LoadBalancer) IPAddressVO(com.cloud.network.dao.IPAddressVO) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

ElasticLbVmMapVO (com.cloud.network.ElasticLbVmMapVO)3 Network (com.cloud.network.Network)2 DomainRouterVO (com.cloud.vm.DomainRouterVO)2 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)1 PublicIp (com.cloud.network.addr.PublicIp)1 IPAddressVO (com.cloud.network.dao.IPAddressVO)1 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)1 ElasticLbVmMapDaoImpl (com.cloud.network.lb.dao.ElasticLbVmMapDaoImpl)1 LoadBalancer (com.cloud.network.rules.LoadBalancer)1