use of org.openkilda.wfm.share.flow.resources.ResourceNotAvailableException in project open-kilda by telstra.
the class TransitVlanPool method allocate.
@TransactionRequired
private TransitVlanEncapsulation allocate(Flow flow, PathId pathId) {
if (nextVlan > 0) {
if (nextVlan <= maxTransitVlan && !transitVlanRepository.exists(nextVlan)) {
return addVlan(flow, pathId, nextVlan++);
} else {
nextVlan = 0;
}
}
// The pool requires (re-)initialization.
if (nextVlan == 0) {
long numOfPools = (maxTransitVlan - minTransitVlan) / poolSize;
if (numOfPools > 1) {
long poolToTake = Math.abs(new Random().nextInt()) % numOfPools;
Optional<Integer> availableVlan = transitVlanRepository.findFirstUnassignedVlan(minTransitVlan + (int) poolToTake * poolSize, minTransitVlan + (int) (poolToTake + 1) * poolSize - 1);
if (availableVlan.isPresent()) {
nextVlan = availableVlan.get();
return addVlan(flow, pathId, nextVlan++);
}
}
// The pool requires full scan.
nextVlan = -1;
}
if (nextVlan == -1) {
Optional<Integer> availableVlan = transitVlanRepository.findFirstUnassignedVlan(minTransitVlan, minTransitVlan);
if (availableVlan.isPresent()) {
nextVlan = availableVlan.get();
return addVlan(flow, pathId, nextVlan++);
}
}
throw new ResourceNotAvailableException("No vlan available");
}
use of org.openkilda.wfm.share.flow.resources.ResourceNotAvailableException in project open-kilda by telstra.
the class VxlanPool method allocate.
@TransactionRequired
private VxlanEncapsulation allocate(Flow flow, PathId pathId) {
if (nextVxlan > 0) {
if (nextVxlan <= maxVxlan && !vxlanRepository.exists(nextVxlan)) {
return addVxlan(flow, pathId, nextVxlan++);
} else {
nextVxlan = 0;
}
}
// The pool requires (re-)initialization.
if (nextVxlan == 0) {
long numOfPools = (maxVxlan - minVxlan) / poolSize;
if (numOfPools > 1) {
long poolToTake = Math.abs(new Random().nextInt()) % numOfPools;
Optional<Integer> availableVxlan = vxlanRepository.findFirstUnassignedVxlan(minVxlan + (int) poolToTake * poolSize, minVxlan + (int) (poolToTake + 1) * poolSize - 1);
if (availableVxlan.isPresent()) {
nextVxlan = availableVxlan.get();
return addVxlan(flow, pathId, nextVxlan++);
}
}
// The pool requires full scan.
nextVxlan = -1;
}
if (nextVxlan == -1) {
Optional<Integer> availableVxlan = vxlanRepository.findFirstUnassignedVxlan(minVxlan, maxVxlan);
if (availableVxlan.isPresent()) {
nextVxlan = availableVxlan.get();
return addVxlan(flow, pathId, nextVxlan++);
}
}
throw new ResourceNotAvailableException("No vxlan available");
}
Aggregations