diff options
author | Stan Bonev <sb5356@att.com> | 2018-07-27 11:49:50 -0400 |
---|---|---|
committer | Stan Bonev <sb5356@att.com> | 2018-07-27 11:49:50 -0400 |
commit | 5d0c8984dc39d465ef6c3ed776213010849d34a5 (patch) | |
tree | 478641f18ef5ccc35dac58804f22de4e063f1c6c /resource-assignment | |
parent | dbb08a26109fbe6cd0b8f96666eeb58cc25ecb03 (diff) |
RA: Add capability to assign new numbers for range
Change-Id: Ibb11219bfe0362055d388a4a10dab81e95979892
Issue-ID: CCSDK-408
Signed-off-by: Stan Bonev <sb5356@att.com>
Diffstat (limited to 'resource-assignment')
9 files changed, 518 insertions, 505 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 426fd289..0e4b9252 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 @@ -60,7 +60,7 @@ public class ResourceAllocator implements SvcLogicResource { @Override public QueryStatus notify(String resource, String action, String key, SvcLogicContext ctx) throws SvcLogicException { - return (QueryStatus.SUCCESS); + return QueryStatus.SUCCESS; } @Override @@ -351,6 +351,8 @@ public class ResourceAllocator implements SvcLogicResource { rr.rangeMinOverride = Integer.parseInt(rangeMinOverrideStr); String rangeMaxOverrideStr = getParam(ctx, "range-max-override", false, "-1"); rr.rangeMaxOverride = Integer.parseInt(rangeMaxOverrideStr); + String rangeForceNewNumbersStr = getParam(ctx, "range-force-new-numbers", false, "false"); + rr.rangeForceNewNumbers = Boolean.parseBoolean(rangeForceNewNumbersStr); 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 af6a2801..b13ef80e 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 @@ -178,6 +178,7 @@ public class DbAllocationRule implements AllocationRule { ar.rangeList.get(ar.rangeList.size() - 1).max = resourceRequest.rangeMaxOverride; } } + ar.forceNewNumbers = resourceRequest.rangeForceNewNumbers; 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 b5c24fa7..a52ce385 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 @@ -30,6 +30,7 @@ public class ResourceRequest { public boolean rangeReverseOrder; public int rangeMinOverride; public int rangeMaxOverride; + public boolean rangeForceNewNumbers; 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 9cae5fee..70092db3 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 @@ -267,7 +267,7 @@ class AllocationFunction extends SynchronizedFunction { // First try to reuse the numbers already taken by the same resource union SortedSet<Integer> uu = RangeUtil.getUsed(rr, req.resourceUnionId); - if (uu != null && !uu.isEmpty() && req.replace) { + if (uu != null && !uu.isEmpty() && req.replace && !req.forceNewNumbers) { if (uu.size() >= req.requestedCount) { // Just take the first req.requestedCount numbers from uu Iterator<Integer> i = uu.iterator(); 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 d87469fd..7b60d368 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 @@ -35,4 +35,5 @@ public class RangeAllocationRequest extends AllocationRequest { public int requestedCount = 1; public boolean sequential = false; public boolean reverseOrder = false; + public boolean forceNewNumbers = false; } diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/util/RangeUtil.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/util/RangeUtil.java index 4685233d..fdc8a2b1 100644 --- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/util/RangeUtil.java +++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/rm/util/RangeUtil.java @@ -76,15 +76,19 @@ public class RangeUtil { found = true; break; } + if (req.forceNewNumbers && rai.used.contains(num)) { + found = true; + break; + } } } - + if (!found) { good = true; break; } } - + return good; } diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java index bba8e2b9..e7b855de 100644 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java +++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java @@ -21,6 +21,7 @@ package jtest.org.onap.ccsdk.sli.adaptors.ra; +import java.util.Date; import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestDb; import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestTable; @@ -31,10 +32,11 @@ public class DataSetup { private TestTable resource = null; private TestTable allocationItem = null; - private static final String[] RESOURCE_COLUMNS = {"asset_id", "resource_name", "resource_type", "lt_used"}; + private static final String[] RESOURCE_COLUMNS = + {"asset_id", "resource_name", "resource_type", "lt_used", "rr_used"}; private static final String[] ALLOCATION_ITEM_COLUMNS = {"resource_id", "application_id", "resource_set_id", - "resource_union_id", "resource_share_group_list", "lt_used", "allocation_time"}; + "resource_union_id", "resource_share_group_list", "lt_used", "rr_used", "allocation_time"}; private void initTables() { if (resource == null) { @@ -51,6 +53,37 @@ public class DataSetup { resource.delete("true"); } + public void setupLimitItem(String resourceName, String assetId, String resourceSetId, String resourceUnionId, + long used) { + initTables(); + + Long rid = resource.getId("asset_id = '" + assetId + "' AND resource_name = '" + resourceName + "'"); + if (rid == null) { + resource.add(assetId, resourceName, "Limit", used, null); + rid = resource.getLastId(); + } + allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, used, null, new Date()); + } + + public void setupRangeItem(String resourceName, String assetId, String resourceSetId, String resourceUnionId, + String used) { + initTables(); + + Long rid = resource.getId("asset_id = '" + assetId + "' AND resource_name = '" + resourceName + "'"); + if (rid == null) { + resource.add(assetId, resourceName, "Range", null, used); + rid = resource.getLastId(); + } + allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, null, used, new Date()); + } + + public boolean checkRangeItem(String resourceName, String assetId, String resourceSetId, String used) { + String where = "resource_id = (SELECT resource_id FROM RESOURCE WHERE resource_name = '" + resourceName + + "' AND asset_id = '" + assetId + "') AND resource_set_id = '" + resourceSetId + "'"; + Object usedInDb = allocationItem.getColumn("rr_used", where); + return used.equals(usedInDb); + } + public void setTestDb(TestDb testDb) { this.testDb = testDb; } 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 c4200751..cdd95dcd 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 @@ -240,398 +240,475 @@ public class TestReserve { }); } - - + + + @Test + public void test003() throws Exception { + String t = "003"; + log.info("============== reserve " + t + " ================================"); + log.info("=== Test successful response - new start - all resources available"); + + ResourceEntity sd = new ResourceEntity(); + sd.resourceEntityId = "gblond2003me6"; + sd.resourceEntityType = "VNF"; + + ResourceTarget rt = new ResourceTarget(); + rt.resourceTargetId = "MDTWNJ21A5"; + rt.resourceTargetType = "Site"; + + + ResourceRequest rr = new ResourceRequest(); + rr.serviceModel = "MY-SERV-MODEL"; + rr.resourceName = "VPE-Cust"; + // rr.requestType = "New"; + // rr.rangeMaxOverride = 5; + // rr.rangeMinOverride = 5; + + List<ResourceResponse> rsList = new ArrayList<>(); + resourceAllocator.reserve(sd, rt, rr, rsList); + + rsList.forEach(r -> { + StrUtil.info(log, r); + }); + + log.info("======================== Query + t =============================="); + rsList = new ArrayList<>(); + resourceAllocator.query(sd, null, rr, rsList); + + rsList.forEach(r -> { + StrUtil.info(log, r); + }); + + } + + + + @Test + public void test004() throws Exception { + String t = "004"; + log.info("============== reserve " + t + " ================================"); + log.info("=== Test successful response - new start - all resources available"); + + ResourceEntity sd = new ResourceEntity(); + sd.resourceEntityId = "gblond2003me6"; + sd.resourceEntityType = "VNF"; + + ResourceTarget rt = new ResourceTarget(); + rt.resourceTargetId = "MDTWNJ21A5"; + rt.resourceTargetType = "Site"; + + List<ResourceRequest> rrs = new ArrayList<>(); + ResourceRequest rr = new ResourceRequest(); + rr.serviceModel = "MY-SERV-MODEL"; + rr.resourceName = "VPE-Cust"; + rrs.add(rr); + + rr = new ResourceRequest(); + rr.serviceModel = "MY-SERV-MODEL"; + rr.resourceName = "VPE-Core1"; + rrs.add(rr); + + rr = new ResourceRequest(); + rr.serviceModel = "MY-SERV-MODEL"; + rr.resourceName = "VPE-Core2"; + rrs.add(rr); + + + + List<ResourceResponse> rsList = new ArrayList<>(); + // resourceAllocator.reserve(sd, rt, rrs, rsList); + + rsList.forEach(r -> { + StrUtil.info(log, r); + }); + + log.info("======================== Query + t =============================="); + rsList = new ArrayList<>(); + resourceAllocator.query(sd, null, rr, rsList); + + rsList.forEach(r -> { + StrUtil.info(log, r); + }); + + } + + + @Test + public void test005() throws Exception { + String t = "005"; + log.info("============== reserve " + t + " ================================"); + log.info("=== Test successful response - new start - all resources available"); + + // String service1 = "reserve" + t + "/service1"; + + dataSetup.cleanup(); + + TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS); + TestTable allocationItem = + new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id", ALLOCATION_ITEM_COLUMNS); + + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); + ctx.setAttribute("ra-input.check-only", "false"); + ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Cust"); + ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); + + ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5"); + ctx.setAttribute("ra-input.reservation-target-type", "Site"); + + ctx.setAttribute("ra-input.resource-name", "cust-vlan-id"); + + + QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); + + Assert.assertTrue(st == QueryStatus.SUCCESS); + + resource.print(); + allocationItem.print(); + + ctx = new SvcLogicContext(); + ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); + ctx.setAttribute("ra-input.check-only", "false"); + ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core1"); + ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); + + ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5"); + ctx.setAttribute("ra-input.reservation-target-type", "Site"); + + ctx.setAttribute("ra-input.resource-name", "vlan-id-inner"); + + + st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); + + Assert.assertTrue(st == QueryStatus.SUCCESS); + + resource.print(); + allocationItem.print(); + + ctx = new SvcLogicContext(); + ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); + ctx.setAttribute("ra-input.check-only", "false"); + ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core2"); + ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); + + ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5"); + ctx.setAttribute("ra-input.reservation-target-type", "Site"); + + ctx.setAttribute("ra-input.resource-name", "vlan-id-inner"); + ctx.setAttribute("ra-input.replace", "false"); + + + st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); + + Assert.assertTrue(st == QueryStatus.SUCCESS); + + resource.print(); + allocationItem.print(); + + + /* Query Using ReservationEntityId using ServiceLogicContext */ + ctx = new SvcLogicContext(); + ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); + ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); + ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core1"); + + + st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx); + Assert.assertTrue(st == QueryStatus.SUCCESS); + + + /* Query Using ReservationTargetId using ServiceLogicContext */ + ctx = new SvcLogicContext(); + ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); + ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5"); + ctx.setAttribute("ra-input.reservation-target-type", "Site"); + ctx.setAttribute("ra-input.resource-name", "vlan-id-inner"); + + st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx); + Assert.assertTrue(st == QueryStatus.SUCCESS); + + log.info("======================== Query Using ResourceEntity=============================="); + /* Query Using ResourceEntity bean */ + ResourceEntity sd = new ResourceEntity(); + sd.resourceEntityId = "gblond2003me6"; + sd.resourceEntityType = "VPE-Core1"; + + + ResourceRequest rr = new ResourceRequest(); + rr.serviceModel = "MY-SERV-MODEL-1"; + rr.resourceName = "vlan-id-inner"; + rr.requestType = "New"; + rr.rangeMaxOverride = -1; + rr.rangeMinOverride = -1; + + List<ResourceResponse> rsList = new ArrayList<>(); + resourceAllocator.query(sd, null, null, rsList); + + rsList.forEach(r -> { + StrUtil.info(log, r); + }); + + /* + * log.info("======================== release Using ResourceEntity=============================="); + * rsList = new ArrayList<ResourceResponse>(); AllocationStatus status = + * resourceAllocator.release(sd); Assert.assertTrue(status == AllocationStatus.Success); + * + * + * log.info("======================== Query Using ResourceEntity=============================="); + * rsList = new ArrayList<ResourceResponse>(); resourceAllocator.query(sd, null, null, rsList); + * + * + * rsList.forEach(r -> { StrUtil.info(log, r); }); + */ + + } + + + @Test - public void test003() throws Exception { - String t = "003"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test successful response - new start - all resources available"); - - ResourceEntity sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VNF"; - - ResourceTarget rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - - ResourceRequest rr= new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - rr.resourceName = "VPE-Cust"; - //rr.requestType = "New"; - //rr.rangeMaxOverride = 5; - //rr.rangeMinOverride = 5; - - List <ResourceResponse> rsList = new ArrayList<ResourceResponse>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - log.info("======================== Query + t =============================="); - rsList = new ArrayList<org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse>(); - resourceAllocator.query(sd, null, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - } - - - - - @Test - public void test004() throws Exception { - String t = "004"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test successful response - new start - all resources available"); - - ResourceEntity sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VNF"; - - ResourceTarget rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - List<ResourceRequest> rrs = new ArrayList<ResourceRequest>(); - ResourceRequest rr= new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - rr.resourceName = "VPE-Cust"; - rrs.add(rr); - - rr= new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - rr.resourceName = "VPE-Core1"; - rrs.add(rr); - - rr= new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - rr.resourceName = "VPE-Core2"; - rrs.add(rr); - - - - List <ResourceResponse> rsList = new ArrayList<ResourceResponse>(); - //resourceAllocator.reserve(sd, rt, rrs, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - log.info("======================== Query + t =============================="); - rsList = new ArrayList<org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse>(); - resourceAllocator.query(sd, null, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - } - - - @Test - public void test005() throws Exception { - String t = "005"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test successful response - new start - all resources available"); - - //String service1 = "reserve" + t + "/service1"; - - dataSetup.cleanup(); - - TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS); - TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id", - ALLOCATION_ITEM_COLUMNS); - - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); - ctx.setAttribute("ra-input.check-only", "false"); - ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Cust"); - ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); - - ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5"); - ctx.setAttribute("ra-input.reservation-target-type", "Site"); - - ctx.setAttribute("ra-input.resource-name", "cust-vlan-id"); - - - QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - resource.print(); - allocationItem.print(); - - ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); - ctx.setAttribute("ra-input.check-only", "false"); - ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core1"); - ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); - - ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5"); - ctx.setAttribute("ra-input.reservation-target-type", "Site"); - - ctx.setAttribute("ra-input.resource-name", "vlan-id-inner"); - - - st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - resource.print(); - allocationItem.print(); - - ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); - ctx.setAttribute("ra-input.check-only", "false"); - ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core2"); - ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); - - ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5"); - ctx.setAttribute("ra-input.reservation-target-type", "Site"); - - ctx.setAttribute("ra-input.resource-name", "vlan-id-inner"); - ctx.setAttribute("ra-input.replace", "false"); - - - st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - resource.print(); - allocationItem.print(); - - - /*Query Using ReservationEntityId using ServiceLogicContext*/ - ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); - ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); - ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core1"); - - - st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx); - Assert.assertTrue(st == QueryStatus.SUCCESS); - - - /*Query Using ReservationTargetId using ServiceLogicContext*/ - ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); - ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5"); - ctx.setAttribute("ra-input.reservation-target-type", "Site"); - ctx.setAttribute("ra-input.resource-name", "vlan-id-inner"); - - st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx); - Assert.assertTrue(st == QueryStatus.SUCCESS); - - log.info("======================== Query Using ResourceEntity=============================="); - /*Query Using ResourceEntity bean*/ - ResourceEntity sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VPE-Core1"; - - - ResourceRequest rr= new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL-1"; - rr.resourceName = "vlan-id-inner"; - rr.requestType = "New"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - - List <ResourceResponse> rsList = new ArrayList<ResourceResponse>(); - resourceAllocator.query(sd, null, null, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - /*log.info("======================== release Using ResourceEntity=============================="); - rsList = new ArrayList<ResourceResponse>(); - AllocationStatus status = resourceAllocator.release(sd); - Assert.assertTrue(status == AllocationStatus.Success); - - - log.info("======================== Query Using ResourceEntity=============================="); - rsList = new ArrayList<ResourceResponse>(); - resourceAllocator.query(sd, null, null, rsList); - - - rsList.forEach(r -> { - StrUtil.info(log, r); - });*/ - - } - - - - @Test - public void test006() throws Exception { - String t = "006"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test successful response - new start - all resources available"); - - ResourceEntity sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VPE-Cust"; - - ResourceTarget rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - - ResourceRequest rr= new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL-1"; - rr.resourceName = "cust-vlan-id"; - - - List <ResourceResponse> rsList = new ArrayList<ResourceResponse>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - log.info("======================== Query + t =============================="); - rsList = new ArrayList<org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse>(); - resourceAllocator.query(sd, null, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - } - - @Test - public void test007() throws Exception { - String t = "007"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test successful response - new start - all resources available"); - - dataSetup.cleanup(); - - TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS); - TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id", - ALLOCATION_ITEM_COLUMNS); - - - ResourceEntity sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VPE"; - sd.resourceEntityVersion = "1"; - - ResourceTarget rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - - ResourceRequest rr= new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - //rr.resourceName = "vlan-id-outer"; - rr.endPointPosition="VPE-Cust"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - - - List <ResourceResponse> rsList = new ArrayList<ResourceResponse>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - //VPE-Core1 - sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VPE"; - sd.resourceEntityVersion = "1"; - - rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - - rr= new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - //rr.resourceName = "vlan-id-filter"; - rr.endPointPosition="VPE-Core1"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - - - rsList = new ArrayList<ResourceResponse>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - - //VPE-Core2 - sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VPE"; - sd.resourceEntityVersion = "1"; - - rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - - rr= new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - //rr.resourceName = "vlan-id-filter"; - rr.endPointPosition="VPE-Core2"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - - - rsList = new ArrayList<ResourceResponse>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - - //VPE-Core3 - sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VPE"; - sd.resourceEntityVersion = "1"; - - rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - - rr= new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - //rr.resourceName = "vlan-id-filter"; - rr.endPointPosition="VPE-Core3"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - - - rsList = new ArrayList<ResourceResponse>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - resource.print(); - allocationItem.print(); - - log.info("======================== Query + t =============================="); - rsList = new ArrayList<org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse>(); - resourceAllocator.query(sd, null, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); - ctx.setAttribute("ra-input.reservation-entity-type", "VPE"); - - - QueryStatus st = resourceAllocator.release("NetworkCapacity", "gblond2003me6", ctx); - Assert.assertTrue(st == QueryStatus.SUCCESS); - - } + public void test006() throws Exception { + String t = "006"; + log.info("============== reserve " + t + " ================================"); + log.info("=== Test successful response - new start - all resources available"); + + ResourceEntity sd = new ResourceEntity(); + sd.resourceEntityId = "gblond2003me6"; + sd.resourceEntityType = "VPE-Cust"; + + ResourceTarget rt = new ResourceTarget(); + rt.resourceTargetId = "MDTWNJ21A5"; + rt.resourceTargetType = "Site"; + + + ResourceRequest rr = new ResourceRequest(); + rr.serviceModel = "MY-SERV-MODEL-1"; + rr.resourceName = "cust-vlan-id"; + + + List<ResourceResponse> rsList = new ArrayList<>(); + resourceAllocator.reserve(sd, rt, rr, rsList); + + rsList.forEach(r -> { + StrUtil.info(log, r); + }); + + log.info("======================== Query + t =============================="); + rsList = new ArrayList<>(); + resourceAllocator.query(sd, null, rr, rsList); + + rsList.forEach(r -> { + StrUtil.info(log, r); + }); + + } + + @Test + public void test007() throws Exception { + String t = "007"; + log.info("============== reserve " + t + " ================================"); + log.info("=== Test successful response - new start - all resources available"); + + dataSetup.cleanup(); + + TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS); + TestTable allocationItem = + new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id", ALLOCATION_ITEM_COLUMNS); + + + ResourceEntity sd = new ResourceEntity(); + sd.resourceEntityId = "gblond2003me6"; + sd.resourceEntityType = "VPE"; + sd.resourceEntityVersion = "1"; + + ResourceTarget rt = new ResourceTarget(); + rt.resourceTargetId = "MDTWNJ21A5"; + rt.resourceTargetType = "Site"; + + + ResourceRequest rr = new ResourceRequest(); + rr.serviceModel = "MY-SERV-MODEL"; + // rr.resourceName = "vlan-id-outer"; + rr.endPointPosition = "VPE-Cust"; + rr.rangeMaxOverride = -1; + rr.rangeMinOverride = -1; + + + List<ResourceResponse> rsList = new ArrayList<>(); + resourceAllocator.reserve(sd, rt, rr, rsList); + + // VPE-Core1 + sd = new ResourceEntity(); + sd.resourceEntityId = "gblond2003me6"; + sd.resourceEntityType = "VPE"; + sd.resourceEntityVersion = "1"; + + rt = new ResourceTarget(); + rt.resourceTargetId = "MDTWNJ21A5"; + rt.resourceTargetType = "Site"; + + + rr = new ResourceRequest(); + rr.serviceModel = "MY-SERV-MODEL"; + // rr.resourceName = "vlan-id-filter"; + rr.endPointPosition = "VPE-Core1"; + rr.rangeMaxOverride = -1; + rr.rangeMinOverride = -1; + + + rsList = new ArrayList<>(); + resourceAllocator.reserve(sd, rt, rr, rsList); + + + // VPE-Core2 + sd = new ResourceEntity(); + sd.resourceEntityId = "gblond2003me6"; + sd.resourceEntityType = "VPE"; + sd.resourceEntityVersion = "1"; + + rt = new ResourceTarget(); + rt.resourceTargetId = "MDTWNJ21A5"; + rt.resourceTargetType = "Site"; + + + rr = new ResourceRequest(); + rr.serviceModel = "MY-SERV-MODEL"; + // rr.resourceName = "vlan-id-filter"; + rr.endPointPosition = "VPE-Core2"; + rr.rangeMaxOverride = -1; + rr.rangeMinOverride = -1; + + + rsList = new ArrayList<>(); + resourceAllocator.reserve(sd, rt, rr, rsList); + + + // VPE-Core3 + sd = new ResourceEntity(); + sd.resourceEntityId = "gblond2003me6"; + sd.resourceEntityType = "VPE"; + sd.resourceEntityVersion = "1"; + + rt = new ResourceTarget(); + rt.resourceTargetId = "MDTWNJ21A5"; + rt.resourceTargetType = "Site"; + + + rr = new ResourceRequest(); + rr.serviceModel = "MY-SERV-MODEL"; + // rr.resourceName = "vlan-id-filter"; + rr.endPointPosition = "VPE-Core3"; + rr.rangeMaxOverride = -1; + rr.rangeMinOverride = -1; + + + rsList = new ArrayList<>(); + resourceAllocator.reserve(sd, rt, rr, rsList); + + rsList.forEach(r -> { + StrUtil.info(log, r); + }); + + resource.print(); + allocationItem.print(); + + log.info("======================== Query + t =============================="); + rsList = new ArrayList<>(); + resourceAllocator.query(sd, null, rr, rsList); + + rsList.forEach(r -> { + StrUtil.info(log, r); + }); + + + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); + ctx.setAttribute("ra-input.reservation-entity-type", "VPE"); + + + QueryStatus st = resourceAllocator.release("NetworkCapacity", "gblond2003me6", ctx); + Assert.assertTrue(st == QueryStatus.SUCCESS); + + } + + @Test + public void test008() throws Exception { + String t = "008"; + log.info("============== reserve " + t + " ================================"); + log.info("=== Test range-force-new-numbers = false"); + + String entityId = "reserve" + t; + String targetId = "port-id-1"; + String resourceName = "cust-vlan-id"; + + String assetId = "VNF::" + targetId; + String resourceUnion = "SI::" + entityId; + String resourceSet1 = resourceUnion + "::1"; + String resourceSet2 = resourceUnion + "::2"; + + dataSetup.cleanup(); + + dataSetup.setupRangeItem(resourceName, assetId, resourceSet1, resourceUnion, "201"); + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("ra-input.service-model", "ADIG"); + ctx.setAttribute("ra-input.check-only", "false"); + + ctx.setAttribute("ra-input.resource-name", resourceName); + ctx.setAttribute("ra-input.range-force-new-numbers", "false"); + + ctx.setAttribute("ra-input.reservation-entity-type", "SI"); + ctx.setAttribute("ra-input.reservation-entity-id", entityId); + ctx.setAttribute("ra-input.reservation-entity-version", "2"); + + ctx.setAttribute("ra-input.reservation-target-id", targetId); + ctx.setAttribute("ra-input.reservation-target-type", "VNF"); + + QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); + + Assert.assertTrue(st == QueryStatus.SUCCESS); + Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet1, "201")); + Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet2, "201")); + } + + @Test + public void test009() throws Exception { + String t = "009"; + log.info("============== reserve " + t + " ================================"); + log.info("=== Test range-force-new-numbers = true"); + + String entityId = "reserve" + t; + String targetId = "port-id-1"; + String resourceName = "cust-vlan-id"; + + String assetId = "VNF::" + targetId; + String resourceUnion = "SI::" + entityId; + String resourceSet1 = resourceUnion + "::1"; + String resourceSet2 = resourceUnion + "::2"; + + dataSetup.cleanup(); + + dataSetup.setupRangeItem(resourceName, assetId, resourceSet1, resourceUnion, "201"); + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("ra-input.service-model", "ADIG"); + ctx.setAttribute("ra-input.check-only", "false"); + + ctx.setAttribute("ra-input.resource-name", resourceName); + ctx.setAttribute("ra-input.range-force-new-numbers", "true"); + + ctx.setAttribute("ra-input.reservation-entity-type", "SI"); + ctx.setAttribute("ra-input.reservation-entity-id", entityId); + ctx.setAttribute("ra-input.reservation-entity-version", "2"); + + ctx.setAttribute("ra-input.reservation-target-id", targetId); + ctx.setAttribute("ra-input.reservation-target-type", "VNF"); + + QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); + + Assert.assertTrue(st == QueryStatus.SUCCESS); + Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet1, "201")); + Assert.assertFalse(dataSetup.checkRangeItem(resourceName, assetId, resourceSet2, "201")); + } } diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/rm/DataSetup.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/rm/DataSetup.java deleted file mode 100644 index 473a99f4..00000000 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/rm/DataSetup.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package jtest.org.onap.ccsdk.sli.adaptors.rm; - -import java.util.Date; - -import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestDb; -import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestTable; - -public class DataSetup { - - private TestDb testDb; - - private TestTable resource = null; - private TestTable allocationItem = null; - - private static final String[] RESOURCE_COLUMNS = - { "asset_id", "resource_name", "resource_type", "lt_used", "ll_label", "ll_reference_count", "rr_used" }; - - private static final String[] ALLOCATION_ITEM_COLUMNS = { - "resource_id", "application_id", "resource_set_id", "resource_union_id", "resource_share_group_list", - "lt_used", "ll_label", "rr_used", "allocation_time" }; - - private void initTables() { - if (resource == null) - resource = testDb.table("RESOURCE", "resource_id", RESOURCE_COLUMNS); - if (allocationItem == null) - allocationItem = testDb.table("ALLOCATION_ITEM", "allocation_item_id", ALLOCATION_ITEM_COLUMNS); - } - - public void cleanup() { - allocationItem.delete("true"); - resource.delete("true"); - } - - public void setupLimitItem( - String resourceName, - String assetId, - String resourceSetId, - String resourceUnionId, - long used) { - initTables(); - - Long rid = resource.getId("asset_id = '" + assetId + "' AND resource_name = '" + resourceName + "'"); - if (rid == null) { - resource.add(assetId, resourceName, "Limit", 1, null, null, null); - rid = resource.getLastId(); - } - allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, used, null, null, new Date()); - } - - public void setupRangeItem( - String resourceName, - String assetId, - String resourceSetId, - String resourceUnionId, - String used) { - initTables(); - - Long rid = resource.getId("asset_id = '" + assetId + "' AND resource_name = '" + resourceName + "'"); - if (rid == null) { - resource.add(assetId, resourceName, "Range", null, null, null, used); - rid = resource.getLastId(); - } - allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, null, null, used, new Date()); - } - - public void setupLabelItem( - String resourceName, - String assetId, - String resourceSetId, - String resourceUnionId, - String label) { - initTables(); - - Long rid = resource.getId("asset_id = '" + assetId + "' AND resource_name = '" + resourceName + "'"); - if (rid == null) { - resource.add(assetId, resourceName, "Label", null, label, 1, null); - rid = resource.getLastId(); - } - allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, null, label, null, new Date()); - } - - public void setTestDb(TestDb testDb) { - this.testDb = testDb; - } -} |