diff options
6 files changed, 171 insertions, 3 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; } diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java index b159127b8..af9508a66 100644 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java +++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java @@ -1,5 +1,6 @@ package jtest.org.onap.ccsdk.sli.adaptors.ra; +import static org.junit.Assert.assertNotNull; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -28,7 +29,6 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestTable; -import static org.junit.Assert.assertNotNull; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:test-context.xml" }) @@ -804,4 +804,118 @@ public class TestReserve { allocationItem.print(); } + + @Test + public void test011() throws Exception { + String t = "011"; + log.info("============== reserve " + t + " ================================"); + log.info("=== Test range-next-in-sequence = true"); + + String entityId = "reserve" + t; + String targetId = "port-id-1"; + String resourceName = "vlan-id-filter"; + + String assetId = "Site::" + targetId; + String resourceUnion = "SI::" + entityId; + String resourceSet = resourceUnion + "::1"; + + dataSetup.cleanup(); + dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008"); + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL"); + ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2"); + ctx.setAttribute("ra-input.check-only", "false"); + + ctx.setAttribute("ra-input.resource-name", resourceName); + ctx.setAttribute("ra-input.range-next-in-sequence", "true"); + + ctx.setAttribute("ra-input.reservation-entity-type", "SI"); + ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test"); + ctx.setAttribute("ra-input.reservation-entity-version", "1"); + + ctx.setAttribute("ra-input.reservation-target-id", targetId); + ctx.setAttribute("ra-input.reservation-target-type", "Site"); + + QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); + + Assert.assertTrue(st == QueryStatus.SUCCESS); + Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1009")); + } + + @Test + public void test012() throws Exception { + String t = "012"; + log.info("============== reserve " + t + " ================================"); + log.info("=== Test range-next-in-sequence = false"); + + String entityId = "reserve" + t; + String targetId = "port-id-1"; + String resourceName = "vlan-id-filter"; + + String assetId = "Site::" + targetId; + String resourceUnion = "SI::" + entityId; + String resourceSet = resourceUnion + "::1"; + + dataSetup.cleanup(); + dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008"); + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL"); + ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2"); + ctx.setAttribute("ra-input.check-only", "false"); + + ctx.setAttribute("ra-input.resource-name", resourceName); + ctx.setAttribute("ra-input.range-next-in-sequence", "false"); + + ctx.setAttribute("ra-input.reservation-entity-type", "SI"); + ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test"); + ctx.setAttribute("ra-input.reservation-entity-version", "1"); + + ctx.setAttribute("ra-input.reservation-target-id", targetId); + ctx.setAttribute("ra-input.reservation-target-type", "Site"); + + QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); + + Assert.assertTrue(st == QueryStatus.SUCCESS); + Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1003")); + } + + @Test + public void test013() throws Exception { + String t = "013"; + log.info("============== reserve " + t + " ================================"); + log.info("=== Test range-next-in-sequence = true - multiple ranges"); + + String entityId = "reserve" + t; + String targetId = "port-id-1"; + String resourceName = "vlan-id-filter"; + + String assetId = "Site::" + targetId; + String resourceUnion = "SI::" + entityId; + String resourceSet = resourceUnion + "::1"; + + dataSetup.cleanup(); + dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008,2205-2221"); + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL"); + ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2"); + ctx.setAttribute("ra-input.check-only", "false"); + + ctx.setAttribute("ra-input.resource-name", resourceName); + ctx.setAttribute("ra-input.range-next-in-sequence", "true"); + + ctx.setAttribute("ra-input.reservation-entity-type", "SI"); + ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test"); + ctx.setAttribute("ra-input.reservation-entity-version", "1"); + + ctx.setAttribute("ra-input.reservation-target-id", targetId); + ctx.setAttribute("ra-input.reservation-target-type", "Site"); + + QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); + + Assert.assertTrue(st == QueryStatus.SUCCESS); + Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "2222")); + } } |