@Override public void release(String vlan, long podId, long accountId) { SearchCriteria<PodVlanVO> sc = VlanPodSearch.create(); sc.setParameters("vlan", vlan); sc.setParameters("podId", podId); sc.setParameters("account", accountId); PodVlanVO vo = findOneIncludingRemovedBy(sc); if (vo == null) { return; } vo.setTakenAt(null); vo.setAccountId(null); update(vo.getId(), vo); }
@Override public PodVlanVO take(long podId, long accountId) { SearchCriteria<PodVlanVO> sc = FreeVlanSearch.create(); sc.setParameters("podId", podId); Date now = new Date(); TransactionLegacy txn = TransactionLegacy.currentTxn(); try { txn.start(); PodVlanVO vo = lockOneRandomRow(sc, true); if (vo == null) { return null; } vo.setTakenAt(now); vo.setAccountId(accountId); update(vo.getId(), vo); txn.commit(); return vo; } catch (Exception e) { throw new CloudRuntimeException("Caught Exception ", e); } }