public static Long getAccountIdForGuestVlan(long vlanDbId) { List<AccountGuestVlanMapVO> accountGuestVlanMaps = s_accountGuestVlanMapDao.listAccountGuestVlanMapsByVlan(vlanDbId); if (accountGuestVlanMaps.isEmpty()) { return null; } else { return accountGuestVlanMaps.get(0).getAccountId(); } }
@Override public String allocateVnet(long dataCenterId, long physicalNetworkId, long accountId, String reservationId, boolean canUseSystemGuestVlans) { ArrayList<Long> dedicatedVlanDbIds = new ArrayList<Long>(); boolean useDedicatedGuestVlans = false; List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(accountId); for (AccountGuestVlanMapVO map : maps) { dedicatedVlanDbIds.add(map.getId()); } if (dedicatedVlanDbIds != null && !dedicatedVlanDbIds.isEmpty()) { useDedicatedGuestVlans = true; DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, dedicatedVlanDbIds); if (vo != null) return vo.getVnet(); } if (!useDedicatedGuestVlans || (useDedicatedGuestVlans && canUseSystemGuestVlans)) { DataCenterVnetVO vo = _vnetAllocDao.take(physicalNetworkId, accountId, reservationId, null); if (vo != null) { return vo.getVnet(); } } return null; }
@Override public int compare(AccountGuestVlanMapVO obj1, AccountGuestVlanMapVO obj2) { List<Integer> vlanTokens1 = getVlanFromRange(obj1.getGuestVlanRange()); List<Integer> vlanTokens2 = getVlanFromRange(obj2.getGuestVlanRange()); return vlanTokens1.get(0).compareTo(vlanTokens2.get(0)); } });
List<Integer> vlanTokens = getVlanFromRange(guestVlanMap.getGuestVlanRange()); int dedicatedStartVlan = vlanTokens.get(0).intValue(); int dedicatedEndVlan = vlanTokens.get(1).intValue(); guestVlanMapId = guestVlanMaps.get(i).getId(); guestVlanMapAccountId = guestVlanMaps.get(i).getAccountId(); List<Integer> vlanTokens1 = getVlanFromRange(guestVlanMaps.get(i).getGuestVlanRange()); List<Integer> vlanTokens2 = getVlanFromRange(guestVlanMaps.get(i + 1).getGuestVlanRange()); if (endVlan == (vlanTokens2.get(0).intValue() - 1) && guestVlanMaps.get(i + 1).getAccountId() == vlanOwnerId) { _datacneterVnet.releaseDedicatedGuestVlans(guestVlanMaps.get(i + 1).getId()); _accountGuestVlanMapDao.remove(guestVlanMaps.get(i + 1).getId()); updatedVlanRange = vlanTokens1.get(0).intValue() + "-" + vlanTokens2.get(1).intValue(); break; if (updatedVlanRange != null) { accountGuestVlanMapVO = _accountGuestVlanMapDao.findById(guestVlanMapId); accountGuestVlanMapVO.setGuestVlanRange(updatedVlanRange); _accountGuestVlanMapDao.update(guestVlanMapId, accountGuestVlanMapVO); } else { accountGuestVlanMapVO = new AccountGuestVlanMapVO(vlanOwner.getAccountId(), physicalNetworkId); accountGuestVlanMapVO.setGuestVlanRange(startVlan + "-" + endVlan); _accountGuestVlanMapDao.persist(accountGuestVlanMapVO); List<Integer> finaVlanTokens = getVlanFromRange(accountGuestVlanMapVO.getGuestVlanRange()); for (int i = finaVlanTokens.get(0).intValue(); i <= finaVlanTokens.get(1).intValue(); i++) { List<DataCenterVnetVO> dataCenterVnet = _datacneterVnet.findVnet(physicalNetwork.getDataCenterId(), physicalNetworkId, Integer.toString(i)); dataCenterVnet.get(0).setAccountGuestVlanMapId(accountGuestVlanMapVO.getId());
sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.EQ); sb.and("guestVlanRange", sb.entity().getGuestVlanRange(), SearchCriteria.Op.EQ); sb.and("physicalNetworkId", sb.entity().getPhysicalNetworkId(), SearchCriteria.Op.EQ); sb.join("physicalnetworkSearch", physicalnetworkSearch, sb.entity().getPhysicalNetworkId(), physicalnetworkSearch.entity().getId(), JoinBuilder.JoinType.INNER);
public AccountGuestVlanMapDaoImpl() { super(); AccountSearch = createSearchBuilder(); AccountSearch.and("accountId", AccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ); AccountSearch.done(); GuestVlanSearch = createSearchBuilder(); GuestVlanSearch.and("guestVlanId", GuestVlanSearch.entity().getId(), SearchCriteria.Op.EQ); GuestVlanSearch.done(); PhysicalNetworkSearch = createSearchBuilder(); PhysicalNetworkSearch.and("physicalNetworkId", PhysicalNetworkSearch.entity().getId(), SearchCriteria.Op.EQ); PhysicalNetworkSearch.done(); }
@Override public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { boolean result = super.configure(name, params); countVnetsDedicatedToAccount = createSearchBuilder(Integer.class); countVnetsDedicatedToAccount.and("dc", countVnetsDedicatedToAccount.entity().getDataCenterId(), SearchCriteria.Op.EQ); countVnetsDedicatedToAccount.and("accountGuestVlanMapId", countVnetsDedicatedToAccount.entity().getAccountGuestVlanMapId(), Op.NNULL); AccountGuestVlanMapSearch = _accountGuestVlanMapDao.createSearchBuilder(); AccountGuestVlanMapSearch.and("accountId", AccountGuestVlanMapSearch.entity().getAccountId(), SearchCriteria.Op.EQ); countVnetsDedicatedToAccount.join("AccountGuestVlanMapSearch", AccountGuestVlanMapSearch, countVnetsDedicatedToAccount.entity().getAccountGuestVlanMapId(), AccountGuestVlanMapSearch.entity().getId(), JoinBuilder.JoinType.INNER); countVnetsDedicatedToAccount.select(null, Func.COUNT, countVnetsDedicatedToAccount.entity().getId()); countVnetsDedicatedToAccount.done(); AccountGuestVlanMapSearch.done(); return result; }
final Long accountGuestVlanMapId = dcVnet.getAccountGuestVlanMapId(); final AccountGuestVlanMapVO map = _accountGuestVlanMapDao.findById(accountGuestVlanMapId); if (map.getAccountId() != owner.getAccountId()) { throw new InvalidParameterValueException("Vlan " + vlanId + " is dedicated to a different account");
@Override @ActionEvent(eventType = EventTypes.EVENT_DEDICATED_GUEST_VLAN_RANGE_RELEASE, eventDescription = "releasing" + " dedicated guest vlan range", async = true) @DB public boolean releaseDedicatedGuestVlanRange(Long dedicatedGuestVlanRangeId) { // Verify dedicated range exists AccountGuestVlanMapVO dedicatedGuestVlan = _accountGuestVlanMapDao.findById(dedicatedGuestVlanRangeId); if (dedicatedGuestVlan == null) { throw new InvalidParameterValueException("Dedicated guest vlan with specified" + " id doesn't exist in the system"); } // Remove dedication for the guest vlan _datacneterVnet.releaseDedicatedGuestVlans(dedicatedGuestVlan.getId()); if (_accountGuestVlanMapDao.remove(dedicatedGuestVlanRangeId)) { return true; } else { return false; } }
String[] vlans = map.getGuestVlanRange().split("-"); Integer dedicatedStartVlan = Integer.parseInt(vlans[0]); Integer dedicatedEndVlan = Integer.parseInt(vlans[1]); if ((start >= dedicatedStartVlan && start <= dedicatedEndVlan) || (end >= dedicatedStartVlan && end <= dedicatedEndVlan)) { throw new InvalidParameterValueException("Vnet range " + map.getGuestVlanRange() + " is dedicated" + " to an account. The specified range " + start + "-" + end + " overlaps with the dedicated range " + " Please release the overlapping dedicated range before deleting the range");
_dataCenterVnetDao.releaseDedicatedGuestVlans(map.getId());