diff options
author | sb5356 <sb5356@att.com> | 2020-06-09 17:11:26 -0400 |
---|---|---|
committer | sb5356 <sb5356@att.com> | 2020-06-09 17:11:26 -0400 |
commit | dde59cf2ebddb71d36a7a9b1ae6a1ecf4a6d2167 (patch) | |
tree | 48899f81fb58aca32095e6eed3ab8822eb844b04 /resource-assignment/provider/src/main/java | |
parent | 3a7b70cb8476f5972196e1b4e5985ad9f1e827bb (diff) |
RA: Add option for sequential number assignment from a range
Change-Id: Ifc967676d7c78063ba9ba67706bd4b98ba1d9115
Issue-ID: CCSDK-2416
Signed-off-by: Stan Bonev <sb5356@att.com>
Diffstat (limited to 'resource-assignment/provider/src/main/java')
5 files changed, 56 insertions, 2 deletions
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java index 19062d53b..10f3e02b7 100644 --- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java +++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java @@ -455,6 +455,8 @@ public class ResourceAllocator implements SvcLogicResource { rr.rangeMaxOverride = Integer.parseInt(rangeMaxOverrideStr); String rangeForceNewNumbersStr = getParam(ctx, "range-force-new-numbers", false, "false"); rr.rangeForceNewNumbers = Boolean.parseBoolean(rangeForceNewNumbersStr); + String rangeNextInSequenceStr = getParam(ctx, "range-next-in-sequence", false, "false"); + rr.rangeNextInSequence = Boolean.parseBoolean(rangeNextInSequenceStr); String replaceStr = getParam(ctx, "replace", false, "true"); rr.replace = Boolean.parseBoolean(replaceStr); rr.applicationId = getParam(ctx, "application-id", false, "SDNC"); diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/alloc/DbAllocationRule.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/alloc/DbAllocationRule.java index 12c02c858..d15b1508f 100644 --- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/alloc/DbAllocationRule.java +++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/alloc/DbAllocationRule.java @@ -242,6 +242,7 @@ public class DbAllocationRule implements AllocationRule { } ar.forceNewNumbers = resourceRequest.rangeForceNewNumbers; + ar.nextInSequence = resourceRequest.rangeNextInSequence; return ar; } diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java index bc05af657..2ebad4c89 100644 --- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java +++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceRequest.java @@ -35,6 +35,7 @@ public class ResourceRequest { public int rangeMinOverride; public int rangeMaxOverride; public boolean rangeForceNewNumbers; + public boolean rangeNextInSequence; public boolean replace; public String requestType; public String serviceModel; diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/AllocationFunction.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/AllocationFunction.java index 0f5335443..5ec7c26ba 100644 --- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/AllocationFunction.java +++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/comp/AllocationFunction.java @@ -108,7 +108,7 @@ class AllocationFunction extends SynchronizedFunction { public void _exec() throws ResourceLockedException { outcome = allocate(request); - if ((outcome!=null) && (outcome.status == AllocationStatus.Success)) { + if (outcome!=null && outcome.status == AllocationStatus.Success) { for (Resource r : updateList) { resourceDao.saveResource(r); } @@ -334,7 +334,56 @@ class AllocationFunction extends SynchronizedFunction { } } - if (req.rangeList != null) { + if (req.rangeList != null && !req.rangeList.isEmpty()) { + if (req.nextInSequence) { + // This means we allocate numbers in ascending sequence, not trying from the beginning + // of the range (leaving possible holes in the sequence of allocated numbers) + // To do that, we go through the ranges from the last towards the first (assuming + // ranges are ordered from smallest to the largest numbers), and within each range, from + // the max towards the min and find the first allocated number. Then we take the next numbers + // in the range (that we already checked are available). + + int rangeIndex; + Range range = null; + int n = 0; + boolean foundAllocated = false; + for (rangeIndex = req.rangeList.size() - 1; !foundAllocated && rangeIndex >= 0; rangeIndex--) { + range = req.rangeList.get(rangeIndex); + for (n = range.max; n >= range.min; n--) { + if (!RangeUtil.checkRange(rr, req, n)) { + foundAllocated = true; + break; + } + } + if (foundAllocated) { + break; + } + } + if (foundAllocated) { + n++; + } + for (; foundCount < req.requestedCount && n <= range.max; n++) { + foundNumbers.add(n); + foundCount++; + } + if (foundCount < req.requestedCount) { + rangeIndex++; + for (; rangeIndex < req.rangeList.size(); rangeIndex++) { + range = req.rangeList.get(rangeIndex); + for (n = range.min; foundCount < req.requestedCount && n <= range.max; n++) { + foundNumbers.add(n); + foundCount++; + } + } + } + // If we could not find enough numbers by going up in sequence, + // reset foundNumbers and foundCount, and go back to the holes + if (foundCount < req.requestedCount) { + foundNumbers = new TreeSet<>(); + foundCount = 0; + } + } + if (req.reverseOrder) { for (int i = req.rangeList.size() - 1; i >= 0; i--) { Range range = req.rangeList.get(i); diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/RangeAllocationRequest.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/RangeAllocationRequest.java index 7b60d3689..a7948b02c 100644 --- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/RangeAllocationRequest.java +++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/data/RangeAllocationRequest.java @@ -36,4 +36,5 @@ public class RangeAllocationRequest extends AllocationRequest { public boolean sequential = false; public boolean reverseOrder = false; public boolean forceNewNumbers = false; + public boolean nextInSequence = false; } |