Search in sources :

Example 51 with VlanVO

use of com.cloud.dc.VlanVO in project cloudstack by apache.

the class ManagementServerImpl method searchForIPAddresses.

@Override
public Pair<List<? extends IpAddress>, Integer> searchForIPAddresses(final ListPublicIpAddressesCmd cmd) {
    final Object keyword = cmd.getKeyword();
    final Long physicalNetworkId = cmd.getPhysicalNetworkId();
    final Long associatedNetworkId = cmd.getAssociatedNetworkId();
    final Long zone = cmd.getZoneId();
    final String address = cmd.getIpAddress();
    final Long vlan = cmd.getVlanId();
    final Boolean forVirtualNetwork = cmd.isForVirtualNetwork();
    final Boolean forLoadBalancing = cmd.isForLoadBalancing();
    final Long ipId = cmd.getId();
    final Boolean sourceNat = cmd.getIsSourceNat();
    final Boolean staticNat = cmd.getIsStaticNat();
    final Long vpcId = cmd.getVpcId();
    final Boolean forDisplay = cmd.getDisplay();
    final Map<String, String> tags = cmd.getTags();
    final String state = cmd.getState();
    Boolean isAllocated = cmd.isAllocatedOnly();
    if (isAllocated == null) {
        isAllocated = Boolean.TRUE;
        if (state != null) {
            isAllocated = Boolean.FALSE;
        }
    }
    final Filter searchFilter = new Filter(IPAddressVO.class, "address", false, cmd.getStartIndex(), cmd.getPageSizeVal());
    final SearchBuilder<IPAddressVO> sb = _publicIpAddressDao.createSearchBuilder();
    Long domainId = null;
    Boolean isRecursive = null;
    final List<Long> permittedAccounts = new ArrayList<Long>();
    ListProjectResourcesCriteria listProjectResourcesCriteria = null;
    if (isAllocated) {
        final Account caller = getCaller();
        final Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(), cmd.isRecursive(), null);
        _accountMgr.buildACLSearchParameters(caller, cmd.getId(), cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
        domainId = domainIdRecursiveListProject.first();
        isRecursive = domainIdRecursiveListProject.second();
        listProjectResourcesCriteria = domainIdRecursiveListProject.third();
        _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    }
    sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
    sb.and("address", sb.entity().getAddress(), SearchCriteria.Op.EQ);
    sb.and("vlanDbId", sb.entity().getVlanId(), SearchCriteria.Op.EQ);
    sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ);
    sb.and("physicalNetworkId", sb.entity().getPhysicalNetworkId(), SearchCriteria.Op.EQ);
    sb.and("associatedNetworkIdEq", sb.entity().getAssociatedWithNetworkId(), SearchCriteria.Op.EQ);
    sb.and("isSourceNat", sb.entity().isSourceNat(), SearchCriteria.Op.EQ);
    sb.and("isStaticNat", sb.entity().isOneToOneNat(), SearchCriteria.Op.EQ);
    sb.and("vpcId", sb.entity().getVpcId(), SearchCriteria.Op.EQ);
    sb.and("state", sb.entity().getState(), SearchCriteria.Op.EQ);
    sb.and("display", sb.entity().isDisplay(), SearchCriteria.Op.EQ);
    if (forLoadBalancing != null && forLoadBalancing) {
        final SearchBuilder<LoadBalancerVO> lbSearch = _loadbalancerDao.createSearchBuilder();
        sb.join("lbSearch", lbSearch, sb.entity().getId(), lbSearch.entity().getSourceIpAddressId(), JoinType.INNER);
        sb.groupBy(sb.entity().getId());
    }
    if (keyword != null && address == null) {
        sb.and("addressLIKE", sb.entity().getAddress(), SearchCriteria.Op.LIKE);
    }
    if (tags != null && !tags.isEmpty()) {
        final SearchBuilder<ResourceTagVO> tagSearch = _resourceTagDao.createSearchBuilder();
        for (int count = 0; count < tags.size(); count++) {
            tagSearch.or().op("key" + String.valueOf(count), tagSearch.entity().getKey(), SearchCriteria.Op.EQ);
            tagSearch.and("value" + String.valueOf(count), tagSearch.entity().getValue(), SearchCriteria.Op.EQ);
            tagSearch.cp();
        }
        tagSearch.and("resourceType", tagSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
        sb.groupBy(sb.entity().getId());
        sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER);
    }
    final SearchBuilder<VlanVO> vlanSearch = _vlanDao.createSearchBuilder();
    vlanSearch.and("vlanType", vlanSearch.entity().getVlanType(), SearchCriteria.Op.EQ);
    sb.join("vlanSearch", vlanSearch, sb.entity().getVlanId(), vlanSearch.entity().getId(), JoinBuilder.JoinType.INNER);
    boolean allocatedOnly = false;
    if (isAllocated != null && isAllocated == true) {
        sb.and("allocated", sb.entity().getAllocatedTime(), SearchCriteria.Op.NNULL);
        allocatedOnly = true;
    }
    VlanType vlanType = null;
    if (forVirtualNetwork != null) {
        vlanType = forVirtualNetwork ? VlanType.VirtualNetwork : VlanType.DirectAttached;
    } else {
        vlanType = VlanType.VirtualNetwork;
    }
    final SearchCriteria<IPAddressVO> sc = sb.create();
    if (isAllocated) {
        _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria);
    }
    sc.setJoinParameters("vlanSearch", "vlanType", vlanType);
    if (tags != null && !tags.isEmpty()) {
        int count = 0;
        sc.setJoinParameters("tagSearch", "resourceType", ResourceObjectType.PublicIpAddress.toString());
        for (final String key : tags.keySet()) {
            sc.setJoinParameters("tagSearch", "key" + String.valueOf(count), key);
            sc.setJoinParameters("tagSearch", "value" + String.valueOf(count), tags.get(key));
            count++;
        }
    }
    if (zone != null) {
        sc.setParameters("dataCenterId", zone);
    }
    if (vpcId != null) {
        sc.setParameters("vpcId", vpcId);
    }
    if (ipId != null) {
        sc.setParameters("id", ipId);
    }
    if (sourceNat != null) {
        sc.setParameters("isSourceNat", sourceNat);
    }
    if (staticNat != null) {
        sc.setParameters("isStaticNat", staticNat);
    }
    if (address == null && keyword != null) {
        sc.setParameters("addressLIKE", "%" + keyword + "%");
    }
    if (address != null) {
        sc.setParameters("address", address);
    }
    if (vlan != null) {
        sc.setParameters("vlanDbId", vlan);
    }
    if (physicalNetworkId != null) {
        sc.setParameters("physicalNetworkId", physicalNetworkId);
    }
    if (associatedNetworkId != null) {
        sc.setParameters("associatedNetworkIdEq", associatedNetworkId);
    }
    if (forDisplay != null) {
        sc.setParameters("display", forDisplay);
    }
    if (state != null) {
        sc.setParameters("state", state);
    }
    final Pair<List<IPAddressVO>, Integer> result = _publicIpAddressDao.searchAndCount(sc, searchFilter);
    return new Pair<List<? extends IpAddress>, Integer>(result.first(), result.second());
}
Also used : Account(com.cloud.user.Account) ArrayList(java.util.ArrayList) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) ResourceTagVO(com.cloud.tags.ResourceTagVO) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) List(java.util.List) VlanVO(com.cloud.dc.VlanVO) VlanType(com.cloud.dc.Vlan.VlanType) Pair(com.cloud.utils.Pair) SSHKeyPair(com.cloud.user.SSHKeyPair) Ternary(com.cloud.utils.Ternary) ListProjectResourcesCriteria(com.cloud.projects.Project.ListProjectResourcesCriteria) Filter(com.cloud.utils.db.Filter) IPAddressVO(com.cloud.network.dao.IPAddressVO)

Example 52 with VlanVO

use of com.cloud.dc.VlanVO in project cloudstack by apache.

the class ResourceLimitManagerImpl method calculatePublicIpForAccount.

private long calculatePublicIpForAccount(long accountId) {
    Long dedicatedCount = 0L;
    Long allocatedCount = 0L;
    List<VlanVO> dedicatedVlans = _vlanDao.listDedicatedVlans(accountId);
    for (VlanVO dedicatedVlan : dedicatedVlans) {
        List<IPAddressVO> ips = _ipAddressDao.listByVlanId(dedicatedVlan.getId());
        dedicatedCount += new Long(ips.size());
    }
    allocatedCount = _ipAddressDao.countAllocatedIPsForAccount(accountId);
    if (dedicatedCount > allocatedCount)
        return dedicatedCount;
    else
        return allocatedCount;
}
Also used : IPAddressVO(com.cloud.network.dao.IPAddressVO) VlanVO(com.cloud.dc.VlanVO)

Example 53 with VlanVO

use of com.cloud.dc.VlanVO in project cloudstack by apache.

the class VlanDaoImpl method listVlansForAccountByType.

@Override
public List<VlanVO> listVlansForAccountByType(Long zoneId, long accountId, VlanType vlanType) {
    //FIXME: use a join statement to improve the performance (should be minor since we expect only one or two)
    List<AccountVlanMapVO> vlanMaps = _accountVlanMapDao.listAccountVlanMapsByAccount(accountId);
    List<VlanVO> result = new ArrayList<VlanVO>();
    for (AccountVlanMapVO acvmvo : vlanMaps) {
        VlanVO vlan = findById(acvmvo.getVlanDbId());
        if (vlan.getVlanType() == vlanType && (zoneId == null || vlan.getDataCenterId() == zoneId)) {
            result.add(vlan);
        }
    }
    return result;
}
Also used : AccountVlanMapVO(com.cloud.dc.AccountVlanMapVO) ArrayList(java.util.ArrayList) VlanVO(com.cloud.dc.VlanVO)

Example 54 with VlanVO

use of com.cloud.dc.VlanVO in project cloudstack by apache.

the class VlanDaoImpl method searchForZoneWideVlans.

@Override
@DB
public List<VlanVO> searchForZoneWideVlans(long dcId, String vlanType, String vlanId) {
    StringBuilder sql = new StringBuilder(FindZoneWideVlans);
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    List<VlanVO> zoneWideVlans = new ArrayList<VlanVO>();
    try (PreparedStatement pstmt = txn.prepareStatement(sql.toString())) {
        if (pstmt != null) {
            pstmt.setLong(1, dcId);
            pstmt.setString(2, vlanType);
            pstmt.setString(3, vlanId);
            try (ResultSet rs = pstmt.executeQuery()) {
                while (rs.next()) {
                    zoneWideVlans.add(toEntityBean(rs, false));
                }
            } catch (SQLException e) {
                throw new CloudRuntimeException("searchForZoneWideVlans:Exception:" + e.getMessage(), e);
            }
        }
        return zoneWideVlans;
    } catch (SQLException e) {
        throw new CloudRuntimeException("searchForZoneWideVlans:Exception:" + e.getMessage(), e);
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) VlanVO(com.cloud.dc.VlanVO) DB(com.cloud.utils.db.DB)

Example 55 with VlanVO

use of com.cloud.dc.VlanVO in project cloudstack by apache.

the class VlanDaoImpl method listVlansForPodByType.

@Override
public List<VlanVO> listVlansForPodByType(long podId, VlanType vlanType) {
    //FIXME: use a join statement to improve the performance (should be minor since we expect only one or two)
    List<PodVlanMapVO> vlanMaps = _podVlanMapDao.listPodVlanMapsByPod(podId);
    List<VlanVO> result = new ArrayList<VlanVO>();
    for (PodVlanMapVO pvmvo : vlanMaps) {
        VlanVO vlan = findById(pvmvo.getVlanDbId());
        if (vlan.getVlanType() == vlanType) {
            result.add(vlan);
        }
    }
    return result;
}
Also used : PodVlanMapVO(com.cloud.dc.PodVlanMapVO) ArrayList(java.util.ArrayList) VlanVO(com.cloud.dc.VlanVO)

Aggregations

VlanVO (com.cloud.dc.VlanVO)58 ArrayList (java.util.ArrayList)22 IPAddressVO (com.cloud.network.dao.IPAddressVO)15 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)14 DB (com.cloud.utils.db.DB)14 HostVO (com.cloud.host.HostVO)11 Network (com.cloud.network.Network)11 Account (com.cloud.user.Account)11 TransactionStatus (com.cloud.utils.db.TransactionStatus)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 List (java.util.List)8 Answer (com.cloud.agent.api.Answer)7 AccountVlanMapVO (com.cloud.dc.AccountVlanMapVO)7 DataCenter (com.cloud.dc.DataCenter)7 PublicIp (com.cloud.network.addr.PublicIp)7 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)6 NetworkVO (com.cloud.network.dao.NetworkVO)6 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)6 NetworkOffering (com.cloud.offering.NetworkOffering)6 TransactionCallbackNoReturn (com.cloud.utils.db.TransactionCallbackNoReturn)6