@Override public boolean mark(long dcId, long podId, String ip) { SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create(); sc.setParameters("pod", podId); sc.setParameters("ipAddress", ip); DataCenterIpAddressVO vo = createForUpdate(); vo.setTakenAt(new Date()); return update(vo, sc) >= 1; }
@Override public int countIpAddressUsage(final String ipAddress, final long podId, final long dcId, final boolean onlyCountAllocated) { SearchCriteria<DataCenterIpAddressVO> sc = createSearchCriteria(); if(onlyCountAllocated) { sc.addAnd("takenAt", SearchCriteria.Op.NNULL); } sc.addAnd("ipAddress", SearchCriteria.Op.EQ, ipAddress); sc.addAnd("podId", SearchCriteria.Op.EQ, podId); sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, dcId); List<DataCenterIpAddressVO> result = listBy(sc); return result.size(); }
@Override public int countIPs(long dcId, boolean onlyCountAllocated) { SearchCriteria<Integer> sc; if (onlyCountAllocated) { sc = AllAllocatedIpCountForDc.create(); } else { sc = AllIpCountForDc.create(); } sc.setParameters("data_center_id", dcId); List<Integer> count = customSearch(sc, null); return count.get(0); }
@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 public boolean deleteIpAddressByPod(long podId) { SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create(); sc.setParameters("pod", podId); return remove(sc) > 0; }
@Override public List<DataCenterIpAddressVO> listByPodIdDcId(long podId, long dcId) { SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create(); sc.setParameters("pod", podId); return listBy(sc); }
public DataCenterIpAddressDaoImpl() { super(); AllFieldsSearch = createSearchBuilder(); AllFieldsSearch.and("ip", AllFieldsSearch.entity().getIpAddress(), SearchCriteria.Op.EQ); AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ); AllFieldsSearch.done(); AllIpCount = createSearchBuilder(Integer.class); AllIpCount.select(null, Func.COUNT, AllIpCount.entity().getId()); AllIpCount.and("pod", AllIpCount.entity().getPodId(), SearchCriteria.Op.EQ); AllIpCount.done(); AllIpCountForDc = createSearchBuilder(Integer.class); AllIpCountForDc.select(null, Func.COUNT, AllIpCountForDc.entity().getId()); AllIpCountForDc.and("data_center_id", AllIpCountForDc.entity().getPodId(), SearchCriteria.Op.EQ); AllIpCountForDc.done(); AllAllocatedIpCount = createSearchBuilder(Integer.class); AllAllocatedIpCount.select(null, Func.COUNT, AllAllocatedIpCount.entity().getId()); AllAllocatedIpCount.and("pod", AllAllocatedIpCount.entity().getPodId(), SearchCriteria.Op.EQ); AllAllocatedIpCount.done(); AllAllocatedIpCountForDc = createSearchBuilder(Integer.class); AllAllocatedIpCountForDc.select(null, Func.COUNT, AllAllocatedIpCountForDc.entity().getId()); AllAllocatedIpCountForDc.and("data_center_id", AllAllocatedIpCountForDc.entity().getDataCenterId(), SearchCriteria.Op.EQ);
@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; }
@Override public boolean deleteIpAddressByPodDc(String ipAddress, long podId, long dcId) { SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create(); sc.setParameters("ipAddress", ipAddress); sc.setParameters("pod", podId); sc.setParameters("dc", dcId); return remove(sc) > 0; }
@Override public List<DataCenterIpAddressVO> listByPodIdDcIdIpAddress(long podId, long dcId, String ipAddress) { SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create(); sc.setParameters("pod", podId); sc.setParameters("ipAddress", ipAddress); return listBy(sc); }
@Override public void releaseIpAddress(long nicId) { if (s_logger.isDebugEnabled()) { s_logger.debug("Releasing ip address for instance=" + nicId); } SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create(); sc.setParameters("instance", nicId); DataCenterIpAddressVO vo = createForUpdate(); vo.setTakenAt(null); vo.setInstanceId(null); vo.setReservationId(null); update(vo, sc); }
@Override public int countIPs(long podId, long dcId, boolean onlyCountAllocated) { SearchCriteria<Integer> sc; if (onlyCountAllocated) { sc = AllAllocatedIpCount.create(); } else { sc = AllIpCount.create(); } sc.setParameters("pod", podId); List<Integer> count = customSearch(sc, null); return count.get(0); }
@Override public void releaseIpAddress(long nicId, String reservationId) { if (s_logger.isDebugEnabled()) { s_logger.debug("Releasing ip address for reservationId=" + reservationId + ", instance=" + nicId); } SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create(); sc.setParameters("instance", nicId); sc.setParameters("reservation", reservationId); DataCenterIpAddressVO vo = createForUpdate(); vo.setTakenAt(null); vo.setInstanceId(null); vo.setReservationId(null); update(vo, sc); }
@Override public void releaseIpAddress(String ipAddress, long dcId, Long instanceId) { if (s_logger.isDebugEnabled()) { s_logger.debug("Releasing ip address: " + ipAddress + " data center " + dcId); } SearchCriteria<DataCenterIpAddressVO> sc = AllFieldsSearch.create(); sc.setParameters("ip", ipAddress); sc.setParameters("dc", dcId); sc.setParameters("instance", instanceId); DataCenterIpAddressVO vo = createForUpdate(); vo.setTakenAt(null); vo.setInstanceId(null); vo.setReservationId(null); update(vo, sc); }