@Override @DB public DataCenterIpAddressVO takeDataCenterIpAddress(long dcId, String reservationId) { SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create(); sc.setParameters("dc", dcId); sc.setParameters("taken", (Date)null); TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); DataCenterIpAddressVO vo = lockOneRandomRow(sc, true); if (vo == null) { txn.rollback(); return null; } vo.setTakenAt(new Date()); vo.setReservationId(reservationId); update(vo.getId(), vo); txn.commit(); return vo; }
@Override @DB public DataCenterIpAddressVO takeIpAddress(long dcId, long podId, long instanceId, String reservationId, boolean forSystemVms) { SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create(); sc.setParameters("pod", podId); sc.setParameters("taken", (Date)null); sc.setParameters("forSystemVms", forSystemVms); TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); DataCenterIpAddressVO vo = lockOneRandomRow(sc, true); // If there is no explicitly created range for system vms and reservation mode is preferred (strictness = false) if (forSystemVms && vo == null && !SystemVmManagementIpReservationModeStrictness.value()) { sc.setParameters("forSystemVms", false); vo = lockOneRandomRow(sc, true); } if (vo == null) { txn.rollback(); return null; } vo.setTakenAt(new Date()); vo.setInstanceId(instanceId); vo.setReservationId(reservationId); update(vo.getId(), vo); txn.commit(); return vo; }
AllIpCount.select(null, Func.COUNT, AllIpCount.entity().getId()); AllIpCount.and("pod", AllIpCount.entity().getPodId(), SearchCriteria.Op.EQ); AllIpCount.done(); AllIpCountForDc.select(null, Func.COUNT, AllIpCountForDc.entity().getId()); AllIpCountForDc.and("data_center_id", AllIpCountForDc.entity().getPodId(), SearchCriteria.Op.EQ); AllIpCountForDc.done(); AllAllocatedIpCount.select(null, Func.COUNT, AllAllocatedIpCount.entity().getId()); AllAllocatedIpCount.and("pod", AllAllocatedIpCount.entity().getPodId(), SearchCriteria.Op.EQ); AllAllocatedIpCount.and("removed", AllAllocatedIpCount.entity().getTakenAt(), SearchCriteria.Op.NNULL); AllAllocatedIpCountForDc.select(null, Func.COUNT, AllAllocatedIpCountForDc.entity().getId()); AllAllocatedIpCountForDc.and("data_center_id", AllAllocatedIpCountForDc.entity().getDataCenterId(), SearchCriteria.Op.EQ); AllAllocatedIpCountForDc.and("removed", AllAllocatedIpCountForDc.entity().getTakenAt(), SearchCriteria.Op.NNULL);
ret.setMacAddress(vo.getMacAddress()); ret.setPodId(vo.getPodId()); ret.setId(vo.getId());