Search in sources :

Example 6 with DataCenterVnetVO

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

the class DedicateGuestVlanRangesTest method runDedicateGuestVlanRangeAllocatedVlans.

void runDedicateGuestVlanRangeAllocatedVlans() throws Exception {
    TransactionLegacy txn = TransactionLegacy.open("runDedicateGuestVlanRangeAllocatedVlans");
    Field dedicateVlanField = _dedicateGuestVlanRangeClass.getDeclaredField("vlan");
    dedicateVlanField.setAccessible(true);
    dedicateVlanField.set(dedicateGuestVlanRangesCmd, "2-5");
    PhysicalNetworkVO physicalNetwork = new PhysicalNetworkVO(1L, 1L, "2-5", "200", 1L, null, "testphysicalnetwork");
    physicalNetwork.addIsolationMethod("VLAN");
    when(networkService._physicalNetworkDao.findById(anyLong())).thenReturn(physicalNetwork);
    List<DataCenterVnetVO> dataCenterList = new ArrayList<DataCenterVnetVO>();
    DataCenterVnetVO dataCenter = new DataCenterVnetVO("2-5", 1L, 1L);
    dataCenter.setAccountId(1L);
    dataCenterList.add(dataCenter);
    when(networkService._datacneterVnet.listAllocatedVnetsInRange(anyLong(), anyLong(), anyInt(), anyInt())).thenReturn(dataCenterList);
    try {
        networkService.dedicateGuestVlanRange(dedicateGuestVlanRangesCmd);
    } catch (Exception e) {
        Assert.assertTrue(e.getMessage().contains("is allocated to a different account"));
    } finally {
        txn.close("runDedicateGuestVlanRangeAllocatedVlans");
    }
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) Field(java.lang.reflect.Field) DataCenterVnetVO(com.cloud.dc.DataCenterVnetVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ArrayList(java.util.ArrayList)

Example 7 with DataCenterVnetVO

use of com.cloud.dc.DataCenterVnetVO in project cosmic by MissionCriticalCloud.

the class DataCenterDaoImpl method allocateVnet.

@Override
public String allocateVnet(final long dataCenterId, final long physicalNetworkId, final long accountId, final String reservationId, final boolean canUseSystemGuestVlans) {
    final ArrayList<Long> dedicatedVlanDbIds = new ArrayList<>();
    boolean useDedicatedGuestVlans = false;
    final List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(accountId);
    for (final AccountGuestVlanMapVO map : maps) {
        dedicatedVlanDbIds.add(map.getId());
    }
    if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) {
        useDedicatedGuestVlans = true;
        final DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, dedicatedVlanDbIds);
        if (vo != null) {
            return vo.getVnet();
        }
    }
    if (!useDedicatedGuestVlans || (useDedicatedGuestVlans && canUseSystemGuestVlans)) {
        final DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, null);
        if (vo != null) {
            return vo.getVnet();
        }
    }
    return null;
}
Also used : AccountGuestVlanMapVO(com.cloud.network.dao.AccountGuestVlanMapVO) DataCenterVnetVO(com.cloud.dc.DataCenterVnetVO) ArrayList(java.util.ArrayList)

Example 8 with DataCenterVnetVO

use of com.cloud.dc.DataCenterVnetVO in project cosmic by MissionCriticalCloud.

the class DataCenterVnetDaoImpl method take.

@Override
@DB
public DataCenterVnetVO take(final long physicalNetworkId, final long accountId, final String reservationId, final List<Long> vlanDbIds) {
    final SearchCriteria<DataCenterVnetVO> sc;
    if (vlanDbIds != null) {
        sc = FreeDedicatedVnetSearch.create();
        sc.setParameters("accountGuestVlanMapId", vlanDbIds.toArray());
    } else {
        sc = FreeVnetSearch.create();
    }
    sc.setParameters("physicalNetworkId", physicalNetworkId);
    final Date now = new Date();
    final TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    final DataCenterVnetVO vo = lockOneRandomRow(sc, true);
    if (vo == null) {
        return null;
    }
    vo.setTakenAt(now);
    vo.setAccountId(accountId);
    vo.setReservationId(reservationId);
    update(vo.getId(), vo);
    txn.commit();
    return vo;
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) DataCenterVnetVO(com.cloud.dc.DataCenterVnetVO) Date(java.util.Date) DB(com.cloud.utils.db.DB)

Example 9 with DataCenterVnetVO

use of com.cloud.dc.DataCenterVnetVO in project cosmic by MissionCriticalCloud.

the class DataCenterVnetDaoImpl method releaseDedicatedGuestVlans.

@Override
public void releaseDedicatedGuestVlans(final Long dedicatedGuestVlanRangeId) {
    final SearchCriteria<DataCenterVnetVO> sc = DedicatedGuestVlanRangeSearch.create();
    sc.setParameters("dedicatedGuestVlanRangeId", dedicatedGuestVlanRangeId);
    final List<DataCenterVnetVO> vnets = listBy(sc);
    for (final DataCenterVnetVO vnet : vnets) {
        vnet.setAccountGuestVlanMapId(null);
        update(vnet.getId(), vnet);
    }
}
Also used : DataCenterVnetVO(com.cloud.dc.DataCenterVnetVO)

Example 10 with DataCenterVnetVO

use of com.cloud.dc.DataCenterVnetVO in project cosmic by MissionCriticalCloud.

the class DataCenterVnetDaoImpl method release.

@Override
public void release(final String vnet, final long physicalNetworkId, final long accountId, final String reservationId) {
    final SearchCriteria<DataCenterVnetVO> sc = VnetDcSearchAllocated.create();
    sc.setParameters("vnet", vnet);
    sc.setParameters("physicalNetworkId", physicalNetworkId);
    sc.setParameters("account", accountId);
    sc.setParameters("reservation", reservationId);
    final DataCenterVnetVO vo = findOneIncludingRemovedBy(sc);
    if (vo == null) {
        return;
    }
    vo.setTakenAt(null);
    vo.setAccountId(null);
    vo.setReservationId(null);
    update(vo.getId(), vo);
}
Also used : DataCenterVnetVO(com.cloud.dc.DataCenterVnetVO)

Aggregations

DataCenterVnetVO (com.cloud.dc.DataCenterVnetVO)22 ArrayList (java.util.ArrayList)16 AccountGuestVlanMapVO (com.cloud.network.dao.AccountGuestVlanMapVO)11 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)9 DB (com.cloud.utils.db.DB)7 List (java.util.List)7 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)6 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 Pair (com.cloud.utils.Pair)4 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)4 Field (java.lang.reflect.Field)4 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)3 Network (com.cloud.network.Network)3 Capability (com.cloud.network.Network.Capability)3 PhysicalNetwork (com.cloud.network.PhysicalNetwork)3 NetworkVO (com.cloud.network.dao.NetworkVO)3 NetworkOffering (com.cloud.offering.NetworkOffering)3 NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)3 TransactionStatus (com.cloud.utils.db.TransactionStatus)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3