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");
}
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations