summaryrefslogtreecommitdiffstats
path: root/resource-assignment/provider/src/test
diff options
context:
space:
mode:
authorJessica Wagantall <jwagantall@linuxfoundation.org>2020-12-01 11:25:35 -0800
committerJessica Wagantall <jwagantall@linuxfoundation.org>2020-12-01 11:25:35 -0800
commit5d2eab72fc4442f14108b41800cec88126913823 (patch)
tree11d79f8dde95d08e55dbdd4c29c7c3d20dd30ba6 /resource-assignment/provider/src/test
parent4f3b3ba8e7a38f008cd78c19df4b40e37ff86aa8 (diff)
parent2173e3e37bbb7648b97bcdfa734508686f176727 (diff)
Merge branch 'master' of /home/jwagantall/linuxfoundation/onap/IT-21112/sli-adaptors
Signed-off-by: Jessica Wagantall <jwagantall@linuxfoundation.org>
Diffstat (limited to 'resource-assignment/provider/src/test')
-rw-r--r--resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java108
-rw-r--r--resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestGetResource.java222
-rw-r--r--resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestLockHelper.java61
-rw-r--r--resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java157
-rw-r--r--resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestRelease.java420
-rw-r--r--resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java964
-rw-r--r--resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestResourceLockNode.java39
-rw-r--r--resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/rm/util/LabelUtilTest.java45
-rw-r--r--resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestDb.java37
-rw-r--r--resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestTable.java135
-rw-r--r--resource-assignment/provider/src/test/resources/log4j.properties26
-rw-r--r--resource-assignment/provider/src/test/resources/sql/data.sql180
-rw-r--r--resource-assignment/provider/src/test/resources/sql/schema.sql201
-rw-r--r--resource-assignment/provider/src/test/resources/test-context.xml153
14 files changed, 2748 insertions, 0 deletions
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
new file mode 100644
index 000000000..9aa3f26c4
--- /dev/null
+++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java
@@ -0,0 +1,108 @@
+/*-
+ * ============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.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;
+
+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", "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", "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() {
+ initTables();
+ 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", 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 resourceShareGroup, 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, resourceShareGroup, null, used, new Date());
+ }
+
+ public void setupRangeItem(String resourceName, String assetId, String resourceSetId, String resourceUnionId,
+ String used) {
+ setupRangeItem(resourceName, assetId, resourceSetId, resourceUnionId, null, used);
+ }
+
+ 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 boolean checkLimitItem(String resourceName, String assetId, String resourceSetId, int used) {
+ String where = "resource_id = (SELECT resource_id FROM RESOURCE WHERE resource_name = '" + resourceName
+ + "' AND asset_id = '" + assetId + "') AND resource_set_id = '" + resourceSetId + "' AND lt_used = "
+ + used;
+ return allocationItem.exists(where);
+ }
+
+ public boolean checkItemNotThere(String resourceName, String assetId, String resourceSetId) {
+ String where = "resource_id = (SELECT resource_id FROM RESOURCE WHERE resource_name = '" + resourceName
+ + "' AND asset_id = '" + assetId + "') AND resource_set_id = '" + resourceSetId + "'";
+ return !allocationItem.exists(where);
+ }
+
+ public void setTestDb(TestDb testDb) {
+ this.testDb = testDb;
+ }
+}
diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestGetResource.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestGetResource.java
new file mode 100644
index 000000000..04ee38115
--- /dev/null
+++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestGetResource.java
@@ -0,0 +1,222 @@
+package jtest.org.onap.ccsdk.sli.adaptors.ra;
+
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:test-context.xml"})
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestGetResource {
+
+ private static final Logger log = LoggerFactory.getLogger(TestGetResource.class);
+
+ @Autowired(required = true)
+ private ResourceAllocator resourceAllocator;
+
+ @Autowired(required = true)
+ private DataSetup dataSetup;
+
+ private void setupResourceData() {
+ dataSetup.cleanup();
+
+ String targetId = "GBLOND2025MG2";
+ String assetId = "Device::" + targetId;
+ String resourceName = "internal-vlan";
+
+ for (int i = 0; i < 5; i++) {
+ String entityId = "TEST" + i;
+
+ String resourceUnion = "EVC::" + entityId;
+ String resourceSet = resourceUnion + "::1";
+
+ dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, String.valueOf(i));
+ }
+
+ for (int i = 0; i < 5; i++) {
+ String entityId = "TEST" + (i + 10);
+
+ String resourceUnion = "EVC::SVLAN::" + entityId;
+ String resourceSet = resourceUnion + "::1";
+
+ dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, String.valueOf(10 + i));
+ }
+
+ for (int i = 0; i < 5; i++) {
+ String entityId = "TEST" + (i + 20);
+
+ String resourceUnion = "EVC::" + entityId;
+ String resourceSet = resourceUnion + "::1";
+ String resourceShareGroup = "SHARE1";
+
+ dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, resourceShareGroup,
+ String.valueOf(20 + i));
+ }
+
+ for (int i = 0; i < 5; i++) {
+ String entityId = "TEST" + (i + 30);
+
+ String resourceUnion = "EVC::SVLAN::" + entityId;
+ String resourceSet = resourceUnion + "::1";
+ String resourceShareGroup = "SHARE1";
+
+ dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, resourceShareGroup,
+ String.valueOf(30 + i));
+ }
+ }
+
+ @Test
+ public void test001() throws Exception {
+
+ String t = "001";
+ log.info("============== get-resource node " + t + " ================================");
+ log.info("=== Test query for resource target - no additional criteria");
+
+ setupResourceData();
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
+ ctx.setAttribute("ra-input.resource-target-type", "Device");
+
+ ctx.setAttribute("ra-input.resource-name", "internal-vlan");
+
+ QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
+ "0, 1, 2, 3, 4, 10, 11, 12, 13, 14, 20, 21, 22, 23, 24, 30, 31, 32, 33, 34");
+ }
+
+ @Test
+ public void test002() throws Exception {
+
+ String t = "002";
+ log.info("============== get-resource node " + t + " ================================");
+ log.info("=== Test query for resource target - with resource entity condition");
+
+ setupResourceData();
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
+ ctx.setAttribute("ra-input.resource-target-type", "Device");
+
+ ctx.setAttribute("ra-input.resource-name", "internal-vlan");
+
+ ctx.setAttribute("ra-input.resource-entity-type-filter", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id-filter", "SVLAN%");
+
+ QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
+ "10, 11, 12, 13, 14, 30, 31, 32, 33, 34");
+ }
+
+ @Test
+ public void test003() throws Exception {
+
+ String t = "003";
+ log.info("============== get-resource node " + t + " ================================");
+ log.info("=== Test query for resource target - with resource share group condition");
+
+ setupResourceData();
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
+ ctx.setAttribute("ra-input.resource-target-type", "Device");
+
+ ctx.setAttribute("ra-input.resource-name", "internal-vlan");
+
+ ctx.setAttribute("ra-input.resource-share-group-filter", "SHARE1");
+
+ QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
+ "20, 21, 22, 23, 24, 30, 31, 32, 33, 34");
+ }
+
+ @Test
+ public void test004() throws Exception {
+
+ String t = "004";
+ log.info("============== get-resource node " + t + " ================================");
+ log.info("=== Test query for resource target - with resource share group condition NULL");
+
+ setupResourceData();
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
+ ctx.setAttribute("ra-input.resource-target-type", "Device");
+
+ ctx.setAttribute("ra-input.resource-name", "internal-vlan");
+
+ ctx.setAttribute("ra-input.resource-share-group-filter", "null");
+
+ QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
+ "0, 1, 2, 3, 4, 10, 11, 12, 13, 14");
+ }
+
+ @Test
+ public void test005() throws Exception {
+
+ String t = "005";
+ log.info("============== get-resource node " + t + " ================================");
+ log.info("=== Test query for resource target - with both resource entity and resource share group conditions");
+
+ setupResourceData();
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
+ ctx.setAttribute("ra-input.resource-target-type", "Device");
+
+ ctx.setAttribute("ra-input.resource-name", "internal-vlan");
+
+ ctx.setAttribute("ra-input.resource-entity-type-filter", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id-filter", "SVLAN%");
+ ctx.setAttribute("ra-input.resource-share-group-filter", "null");
+
+ QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "10, 11, 12, 13, 14");
+ }
+}
diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestLockHelper.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestLockHelper.java
new file mode 100644
index 000000000..a9389b279
--- /dev/null
+++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestLockHelper.java
@@ -0,0 +1,61 @@
+package jtest.org.onap.ccsdk.sli.adaptors.ra;
+
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.onap.ccsdk.sli.adaptors.lock.comp.LockHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import static org.junit.Assert.assertNotNull;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath:test-context.xml" })
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestLockHelper {
+
+ private static final Logger log = LoggerFactory.getLogger(TestLockHelper.class);
+
+ @Autowired
+ private LockHelper lockHelper;
+
+ @Test
+ public void test1() throws Exception {
+ LockThread t1 = new LockThread("req1");
+ LockThread t2 = new LockThread("req2");
+ LockThread t3 = new LockThread("req3");
+
+ t1.start();
+ t2.start();
+ t3.start();
+
+ t1.join();
+ t2.join();
+ t3.join();
+ assertNotNull(t1);
+ }
+
+ private class LockThread extends Thread {
+ private String requester;
+
+ public LockThread(String requester) {
+ this.requester = requester;
+ }
+
+ @Override
+ public void run() {
+ lockHelper.lock("resource1", requester, 20);
+
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ log.warn("Thread interrupted: " + e.getMessage(), e);
+ }
+
+ lockHelper.unlock("resource1", false);
+ }
+ }
+}
diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java
new file mode 100644
index 000000000..f31a3859a
--- /dev/null
+++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java
@@ -0,0 +1,157 @@
+package jtest.org.onap.ccsdk.sli.adaptors.ra;
+
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:test-context.xml"})
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestQueryResource {
+
+ private static final Logger log = LoggerFactory.getLogger(TestQueryResource.class);
+
+ @Autowired(required = true)
+ private ResourceAllocator resourceAllocator;
+
+ @Autowired(required = true)
+ private DataSetup dataSetup;
+
+ private void setupResourceData() {
+ dataSetup.cleanup();
+
+ for (int k = 0; k < 6; k++) {
+ String assetId = "Port::TESTPORT-" + (k / 2 + 1) + "-" + (k + 1);
+
+ for (int i = 0; i < 5; i++) {
+ String entityId = "TEST-" + i + "-" + (k / 2 + 1);
+
+ String resourceUnion = "EVC::" + entityId;
+ String resourceSet = resourceUnion + "::1";
+
+ dataSetup.setupRangeItem("test-range-1", assetId, resourceSet, resourceUnion, String.valueOf(i));
+ }
+ }
+
+ for (int k = 0; k < 6; k++) {
+ String assetId = "Port::TESTPORT-" + (k / 2 + 1) + "-" + (k + 1);
+
+ for (int i = 0; i < 5; i++) {
+ String entityId = "TEST-" + i + "-" + (k / 2 + 1);
+
+ String resourceUnion = "EVC::" + entityId;
+ String resourceSet = resourceUnion + "::1";
+
+ dataSetup.setupLimitItem("test-limit-1", assetId, resourceSet, resourceUnion, (i + 1) * 100);
+ }
+ }
+ }
+
+ @Test
+ public void test001() throws Exception {
+
+ String t = "001";
+ log.info("============== query node " + t + " ================================");
+ log.info("=== Test query for resources - with resource target condition - range");
+
+ setupResourceData();
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id-filter", "TESTPORT-1-%");
+ ctx.setAttribute("ra-input.resource-target-type-filter", "Port");
+
+ ctx.setAttribute("ra-input.resource-name", "test-range-1");
+
+ QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "test-range-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Port");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "TESTPORT-1-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "0, 1, 2, 3, 4");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-name"), "test-range-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-target-type"), "Port");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-target-id"), "TESTPORT-1-2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocated"), "0, 1, 2, 3, 4");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list_length"), "5");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[0].resource-entity-type"), "EVC");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[0].resource-entity-id"), "TEST-0-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[0].resource-entity-version"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[0].allocated"), "0");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[1].resource-entity-type"), "EVC");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[1].resource-entity-id"), "TEST-1-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[1].resource-entity-version"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[1].allocated"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[2].resource-entity-type"), "EVC");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[2].resource-entity-id"), "TEST-2-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[2].resource-entity-version"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[2].allocated"), "2");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[3].resource-entity-type"), "EVC");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[3].resource-entity-id"), "TEST-3-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[3].resource-entity-version"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[3].allocated"), "3");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[4].resource-entity-type"), "EVC");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[4].resource-entity-id"), "TEST-4-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[4].resource-entity-version"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[4].allocated"), "4");
+ }
+
+ @Test
+ public void test002() throws Exception {
+
+ String t = "002";
+ log.info("============== query node " + t + " ================================");
+ log.info("=== Test query for resources - with resource target condition - limit");
+
+ setupResourceData();
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-target-id-filter", "TESTPORT-%-1");
+ ctx.setAttribute("ra-input.resource-target-type-filter", "Port");
+
+ ctx.setAttribute("ra-input.resource-name", "test-limit-1");
+
+ QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "test-limit-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Port");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "TESTPORT-1-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "1500");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list_length"), "5");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[0].resource-entity-type"), "EVC");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[0].resource-entity-id"), "TEST-0-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[0].resource-entity-version"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[0].allocated"), "100");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[1].resource-entity-type"), "EVC");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[1].resource-entity-id"), "TEST-1-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[1].resource-entity-version"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[1].allocated"), "200");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[2].resource-entity-type"), "EVC");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[2].resource-entity-id"), "TEST-2-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[2].resource-entity-version"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[2].allocated"), "300");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[3].resource-entity-type"), "EVC");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[3].resource-entity-id"), "TEST-3-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[3].resource-entity-version"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[3].allocated"), "400");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[4].resource-entity-type"), "EVC");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[4].resource-entity-id"), "TEST-4-1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[4].resource-entity-version"), "1");
+ Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[4].allocated"), "500");
+ }
+}
diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestRelease.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestRelease.java
new file mode 100644
index 000000000..88ec586e8
--- /dev/null
+++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestRelease.java
@@ -0,0 +1,420 @@
+package jtest.org.onap.ccsdk.sli.adaptors.ra;
+
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:test-context.xml"})
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestRelease {
+
+ private static final Logger log = LoggerFactory.getLogger(TestRelease.class);
+
+ @Autowired(required = true)
+ private ResourceAllocator resourceAllocator;
+
+ @Autowired(required = true)
+ private DataSetup dataSetup;
+
+ private void setupResourceData() {
+ dataSetup.cleanup();
+
+ dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-1::1", "EVC::TEST-1", "1");
+
+ dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-2::1", "EVC::TEST-2", "2");
+ dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-2::2", "EVC::TEST-2", "2");
+
+ dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "EVC::TEST-3", "3");
+ dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "EVC::TEST-3", "4");
+
+ dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::1", "EVC::TEST-4", "5");
+ dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::2", "EVC::TEST-4", "5");
+ dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::3", "EVC::TEST-4", "6");
+
+ dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-1::1", "EVC::TEST-1", "1");
+
+ dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "EVC::TEST-3", "3");
+ dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "EVC::TEST-3", "4");
+
+ dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-5::1", "EVC::TEST-5", "5");
+
+ dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-6::1", "EVC::TEST-6", "6-20");
+
+ dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-1::1", "EVC::TEST-1", 100);
+
+ dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-2::1", "EVC::TEST-2", 200);
+ dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-2::2", "EVC::TEST-2", 200);
+
+ dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "EVC::TEST-3", 300);
+ dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "EVC::TEST-3", 400);
+
+ dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::1", "EVC::TEST-4", 500);
+ dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::2", "EVC::TEST-4", 500);
+ dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::3", "EVC::TEST-4", 600);
+
+ dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-1::1", "EVC::TEST-1", 100);
+
+ dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "EVC::TEST-3", 300);
+ dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "EVC::TEST-3", 400);
+
+ dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-5::1", "EVC::TEST-5", 500);
+
+ dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-6::1", "EVC::TEST-6", 1000);
+ }
+
+ @Test
+ public void test001() throws Exception {
+
+ String t = "001";
+ log.info("============== release node " + t + " ================================");
+ log.info("=== Test release - with resource set");
+
+ setupResourceData();
+
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::1", "5"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::2", "5"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::3", "6"));
+
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::1", 500));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::2", 500));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::3", 600));
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-entity-type", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id", "TEST-4");
+ ctx.setAttribute("ra-input.resource-entity-version", "2");
+
+ QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::1", "5"));
+ Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::2", "5"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::3", "6"));
+
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::1", 500));
+ Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::2", 500));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::3", 600));
+ }
+
+ @Test
+ public void test002() throws Exception {
+
+ String t = "002";
+ log.info("============== query node " + t + " ================================");
+ log.info("=== Test release - with resource union");
+
+ setupResourceData();
+
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::1", "5"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::2", "5"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::3", "6"));
+
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::1", 500));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::2", 500));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::3", 600));
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-entity-type", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id", "TEST-4");
+
+ QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::1", "5"));
+ Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::2", "5"));
+ Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::3", "6"));
+
+ Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::1", 500));
+ Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::2", 500));
+ Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::3", 600));
+ }
+
+ @Test
+ public void test003() throws Exception {
+
+ String t = "003";
+ log.info("============== release node " + t + " ================================");
+ log.info("=== Test release - with resource set on 2 ports");
+
+ setupResourceData();
+
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4"));
+
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400));
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-entity-type", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id", "TEST-3");
+ ctx.setAttribute("ra-input.resource-entity-version", "1");
+
+ QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4"));
+ Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4"));
+
+ Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400));
+ Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400));
+ }
+
+ @Test
+ public void test004() throws Exception {
+
+ String t = "004";
+ log.info("============== release node " + t + " ================================");
+ log.info("=== Test release - with resource union on 2 ports");
+
+ setupResourceData();
+
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4"));
+
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400));
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-entity-type", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id", "TEST-3");
+
+ QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3"));
+ Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4"));
+ Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3"));
+ Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4"));
+
+ Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300));
+ Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400));
+ Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300));
+ Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400));
+ }
+
+ @Test
+ public void test005() throws Exception {
+
+ String t = "005";
+ log.info("============== release node " + t + " ================================");
+ log.info("=== Test release - with resource set and asset");
+
+ setupResourceData();
+
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4"));
+
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400));
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-entity-type", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id", "TEST-3");
+ ctx.setAttribute("ra-input.resource-entity-version", "1");
+
+ ctx.setAttribute("ra-input.resource-target-type", "Port");
+ ctx.setAttribute("ra-input.resource-target-id", "TESTPORT-1");
+
+ QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4"));
+
+ Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400));
+ }
+
+ @Test
+ public void test006() throws Exception {
+
+ String t = "006";
+ log.info("============== release node " + t + " ================================");
+ log.info("=== Test release - with resource union on 2 ports");
+
+ setupResourceData();
+
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4"));
+
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400));
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-entity-type", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id", "TEST-3");
+
+ ctx.setAttribute("ra-input.resource-target-type", "Port");
+ ctx.setAttribute("ra-input.resource-target-id", "TESTPORT-1");
+
+ QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3"));
+ Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3"));
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4"));
+
+ Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300));
+ Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300));
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400));
+ }
+
+ @Test
+ public void test007() throws Exception {
+
+ String t = "007";
+ log.info("============== release node " + t + " ================================");
+ log.info("=== Test release - partial release of range");
+
+ setupResourceData();
+
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-6::1", "6-20"));
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-entity-type", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id", "TEST-6");
+ ctx.setAttribute("ra-input.resource-entity-version", "1");
+
+ ctx.setAttribute("ra-input.resource-target-type", "Port");
+ ctx.setAttribute("ra-input.resource-target-id", "TESTPORT-2");
+
+ ctx.setAttribute("ra-input.resource-name", "test-range-1");
+ ctx.setAttribute("ra-input.range-release-numbers", "7,9,15-17");
+
+ QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-6::1", "6,8,10-14,18-20"));
+ }
+
+ @Test
+ public void test008() throws Exception {
+
+ String t = "008";
+ log.info("============== release node " + t + " ================================");
+ log.info("=== Test release - partial release of range, but release all numbers");
+
+ setupResourceData();
+
+ Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-6::1", "6-20"));
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-entity-type", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id", "TEST-6");
+ ctx.setAttribute("ra-input.resource-entity-version", "1");
+
+ ctx.setAttribute("ra-input.resource-target-type", "Port");
+ ctx.setAttribute("ra-input.resource-target-id", "TESTPORT-2");
+
+ ctx.setAttribute("ra-input.resource-name", "test-range-1");
+ ctx.setAttribute("ra-input.range-release-numbers", "6-25");
+
+ QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertTrue(dataSetup.checkItemNotThere("test-range-1", "Port::TESTPORT-2", "EVC::TEST-6::1"));
+ }
+
+ @Test
+ public void test009() throws Exception {
+
+ String t = "009";
+ log.info("============== release node " + t + " ================================");
+ log.info("=== Test release - partial release of limit");
+
+ setupResourceData();
+
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-6::1", 1000));
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-entity-type", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id", "TEST-6");
+ ctx.setAttribute("ra-input.resource-entity-version", "1");
+
+ ctx.setAttribute("ra-input.resource-target-type", "Port");
+ ctx.setAttribute("ra-input.resource-target-id", "TESTPORT-2");
+
+ ctx.setAttribute("ra-input.resource-name", "test-limit-1");
+ ctx.setAttribute("ra-input.limit-release-amount", "200");
+
+ QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-6::1", 800));
+ }
+
+ @Test
+ public void test010() throws Exception {
+
+ String t = "010";
+ log.info("============== release node " + t + " ================================");
+ log.info("=== Test release - partial release of limit, but release big number");
+
+ setupResourceData();
+
+ Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-6::1", 1000));
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("ra-input.resource-entity-type", "EVC");
+ ctx.setAttribute("ra-input.resource-entity-id", "TEST-6");
+ ctx.setAttribute("ra-input.resource-entity-version", "1");
+
+ ctx.setAttribute("ra-input.resource-target-type", "Port");
+ ctx.setAttribute("ra-input.resource-target-id", "TESTPORT-2");
+
+ ctx.setAttribute("ra-input.resource-name", "test-limit-1");
+ ctx.setAttribute("ra-input.limit-release-amount", "2000");
+
+ QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ Assert.assertTrue(dataSetup.checkItemNotThere("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-6::1"));
+ }
+}
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
new file mode 100644
index 000000000..dbf0c4aac
--- /dev/null
+++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java
@@ -0,0 +1,964 @@
+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;
+import java.util.List;
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
+import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceEntity;
+import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceRequest;
+import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse;
+import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceTarget;
+import org.onap.ccsdk.sli.adaptors.rm.data.AllocationStatus;
+import org.onap.ccsdk.sli.adaptors.rm.data.Range;
+import org.onap.ccsdk.sli.adaptors.rm.data.ResourceType;
+import org.onap.ccsdk.sli.adaptors.util.str.StrUtil;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+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;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath:test-context.xml" })
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestReserve {
+
+ private static final Logger log = LoggerFactory.getLogger(TestReserve.class);
+
+ private JdbcTemplate jdbcTemplate;
+
+ private static final String[] RESOURCE_COLUMNS = { "asset_id", "resource_name", "resource_type", "lt_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" };
+
+ @Autowired
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
+
+ @Autowired(required = true)
+ private ResourceAllocator resourceAllocator;
+
+ /*
+ * @Autowired(required = true) private ResourceAllocatorApi
+ * resourceAllocatorApi;
+ */
+
+ @Autowired(required = true)
+ private DataSetup dataSetup;
+
+ @Test
+ public void test001() throws Exception {
+ String t = "001";
+ 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", "ADIG");
+ ctx.setAttribute("ra-input.check-only", "false");
+ ctx.setAttribute("ra-input.reservation-entity-type", "SI");
+ ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456");
+ ctx.setAttribute("ra-input.reservation-entity-data.service-speed", "100");
+ ctx.setAttribute("ra-input.reservation-entity-data.service-speed-unit", "Mbps");
+
+ ctx.setAttribute("ra-input.reservation-target-data.vnf-type", "VPE");
+ ctx.setAttribute("ra-input.reservation-target-data.vpe-name", "mdt300vpe54");
+ ctx.setAttribute("ra-input.reservation-target-id", "mdt300vpe54");
+ ctx.setAttribute("ra-input.reservation-target-type", "VNF");
+
+ ctx.setAttribute("ra-input.reservation-target-data.max-vpe-bandwidth-mbps", "5000");
+
+ QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ resource.print();
+ allocationItem.print();
+
+ ctx.setAttribute("ra-input.service-model", "ADIG");
+ ctx.setAttribute("ra-input.check-only", "false");
+ ctx.setAttribute("ra-input.reservation-entity-type", "SI");
+ ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456");
+ ctx.setAttribute("ra-input.reservation-entity-data.service-speed", "100");
+ ctx.setAttribute("ra-input.reservation-entity-data.service-speed-unit", "Mbps");
+
+ ctx.setAttribute("ra-input.reservation-target-data.service-speed", "100");
+ ctx.setAttribute("ra-input.reservation-target-data.service-speed-unit", "Mbps");
+ ctx.setAttribute("ra-input.reservation-target-id", "ICORESITEID-123456");
+ ctx.setAttribute("ra-input.reservation-target-type", "Port");
+
+ st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx);
+
+ Assert.assertTrue(st == QueryStatus.SUCCESS);
+
+ ctx.setAttribute("ra-input.service-model", "ADIG");
+ ctx.setAttribute("ra-input.check-only", "false");
+ ctx.setAttribute("ra-input.reservation-entity-type", "SI");
+ ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456");
+ ctx.setAttribute("ra-input.reservation-entity-data.service-speed", "100");
+ ctx.setAttribute("ra-input.reservation-entity-data.service-speed-unit", "Mbps");
+
+ ctx.setAttribute("ra-input.reservation-target-data.vnf-type", "VPE");
+ ctx.setAttribute("ra-input.reservation-target-data.vpe-name", "mdt300vpe54");
+ ctx.setAttribute("ra-input.reservation-target-id", "mdt300vpe54");
+ ctx.setAttribute("ra-input.reservation-target-type", "AffinityLink");
+
+ 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", "ADIG");
+ ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456");
+ ctx.setAttribute("ra-input.reservation-entity-type", "SI");
+
+ 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", "ADIG");
+ ctx.setAttribute("ra-input.reservation-target-id", "ICORESITEID-123456");
+ ctx.setAttribute("ra-input.reservation-target-type", "Port");
+ ctx.setAttribute("ra-input.resource-name", "Bandwidth");
+
+ 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 = "ICOREPVCID-123456";
+ sd.resourceEntityType = "SI";
+
+ ResourceRequest rr = new ResourceRequest();
+ rr.serviceModel = "ADIG";
+ rr.resourceName = "cust-vlan-id";
+ 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<>();
+ AllocationStatus status = resourceAllocator.release(sd);
+ Assert.assertTrue(status == AllocationStatus.Success);
+
+ log.info("======================== Query Using ResourceEntity==============================");
+ rsList = new ArrayList<>();
+ resourceAllocator.query(sd, null, null, rsList);
+
+ rsList.forEach(r -> {
+ StrUtil.info(log, r);
+ });
+
+ }
+
+ @Test
+ public void test002() throws Exception {
+ String t = "002";
+ log.info("============== reserve " + t + " ================================");
+ log.info("=== Test successful response - new start - all resources available");
+
+ Map<String, String> data = new HashMap<>();
+ data.put("service-speed", "100");
+ data.put("service-speed-unit", "Mbps");
+
+ ResourceEntity sd = new ResourceEntity();
+ sd.resourceEntityId = "ICOREPVCID-123456";
+ sd.resourceEntityType = "SI";
+ sd.data = data;
+
+ data = new HashMap<>();
+ data.put("vnf-type", "VPE");
+ data.put("vpe-name", "mdt300vpe54");
+ data.put("max-vpe-bandwidth-mbps", "5000");
+
+ ResourceTarget rt = new ResourceTarget();
+ rt.resourceTargetId = "mdt300vpe54";
+ rt.resourceTargetType = "VNF";
+ rt.data = data;
+
+ ResourceRequest rr = new ResourceRequest();
+ rr.serviceModel = "ADIG";
+ // rr.resourceName = "cust-vlan-id";
+ rr.requestType = "New";
+ rr.rangeMaxOverride = -1;
+ rr.rangeMinOverride = -1;
+ rr.applicationId = "myapp";
+
+ 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);
+ });
+ assertNotNull(rsList);
+
+ }
+
+ @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);
+ });
+ assertNotNull(sd);
+
+ }
+
+ @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);
+ });
+ assertNotNull(rr);
+
+ }
+
+ @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 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);
+ });
+ assertNotNull(rsList);
+
+ }
+
+ @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;
+ rr.applicationId = "myapp";
+
+ 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;
+ rr.applicationId = "myapp";
+
+ 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;
+ rr.applicationId = "myapp";
+
+ 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;
+ rr.applicationId = "myapp";
+
+ 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"));
+
+ Assert.assertEquals(ctx.getAttribute("resource-list_length"), "1");
+ Assert.assertEquals(ctx.getAttribute("resource-list[0].resource-name"), "cust-vlan-id");
+ Assert.assertEquals(ctx.getAttribute("resource-list[0].resource-target-type"), "VNF");
+ Assert.assertEquals(ctx.getAttribute("resource-list[0].resource-target-id"), "port-id-1");
+ Assert.assertEquals(ctx.getAttribute("resource-list[0].status"), "Success");
+ Assert.assertEquals(ctx.getAttribute("resource-list[0].allocated"), "201");
+ Assert.assertEquals(ctx.getAttribute("resource-list[0].used"), "201");
+ Assert.assertEquals(ctx.getAttribute("resource-list[0].range-list_length"), "1");
+ Assert.assertEquals(ctx.getAttribute("resource-list[0].range-list[0].min"), "2");
+ Assert.assertEquals(ctx.getAttribute("resource-list[0].range-list[0].max"), "1000");
+ }
+
+ @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"));
+ }
+
+ @Test
+ public void test0010_vlantag_with_resourcemodel() throws Exception {
+
+ String t = "0010";
+ log.info("============== reserve " + t + " ================================");
+
+ 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 = "VNF";
+ sd.resourceEntityVersion = "1";
+
+ ResourceTarget rt = new ResourceTarget();
+ rt.resourceTargetId = "MDTWNJ21A5";
+ rt.resourceTargetType = "Site";
+
+ ResourceRequest rr = new ResourceRequest();
+ rr.serviceModel = "MY-SERV-MODEL_3456";
+ rr.resourceName = "vlan-id-outer";
+ rr.endPointPosition = "VPE-Core1";
+ rr.rangeMaxOverride = 3901;
+ rr.rangeMinOverride = 3900;
+ rr.resourceType = ResourceType.Range;
+ rr.applicationId = "myapp";
+
+ List<ResourceResponse> rsList = new ArrayList<>();
+ resourceAllocator.reserve(sd, rt, rr, rsList);
+
+ resource.print();
+ allocationItem.print();
+
+ Range range = new Range();
+ range.min = 3900;
+ range.max = 3901;
+
+ sd = new ResourceEntity();
+ sd.resourceEntityId = "gblond2003me6";
+ sd.resourceEntityType = "VNF";
+ sd.resourceEntityVersion = "1";
+
+ rt = new ResourceTarget();
+ rt.resourceTargetId = "MDTWNJ21A5";
+ rt.resourceTargetType = "Site";
+
+ rr = new ResourceRequest();
+ rr.serviceModel = "MY-SERV-MODEL_3456";
+ rr.resourceName = "vlan-id-outer";
+ rr.endPointPosition = "VPE-Core2";
+ rr.rangeMaxOverride = -1;
+ rr.rangeMinOverride = -1;
+ rr.rangeOverrideList = Arrays.asList(range);
+ rr.resourceType = ResourceType.Range;
+ rr.applicationId = "myapp";
+
+ rsList = new ArrayList<>();
+ resourceAllocator.reserve(sd, rt, rr, rsList);
+
+ resource.print();
+ allocationItem.print();
+
+ sd = new ResourceEntity();
+ sd.resourceEntityId = "gblond2003me6";
+ sd.resourceEntityType = "VNF";
+ sd.resourceEntityVersion = "1";
+
+ rt = new ResourceTarget();
+ rt.resourceTargetId = "MDTWNJ21A5";
+ rt.resourceTargetType = "Site";
+
+ Range range1 = new Range();
+ range1.min = 3900;
+ range1.max = 3901;
+
+ Range range2 = new Range();
+ range2.min = 3904;
+ range2.max = 3905;
+
+ rr = new ResourceRequest();
+ rr.serviceModel = "MY-SERV-MODEL_3456";
+ rr.resourceName = "vlan-id-outer";
+ rr.endPointPosition = "VPE-Core3";
+ rr.rangeMaxOverride = -1;
+ rr.rangeMinOverride = -1;
+ rr.rangeOverrideList = new ArrayList<>();
+ rr.rangeOverrideList.add(range1);
+ rr.rangeOverrideList.add(range2);
+ rr.applicationId = "myapp";
+ rr.resourceType = ResourceType.Range;
+
+ rsList = new ArrayList<>();
+ AllocationStatus status = resourceAllocator.reserve(sd, rt, rr, rsList);
+ Assert.assertTrue(status == AllocationStatus.Success);
+
+ resource.print();
+ allocationItem.print();
+
+ sd = new ResourceEntity();
+ sd.resourceEntityId = "gblond2003me6";
+ sd.resourceEntityType = "VNF";
+ sd.resourceEntityVersion = "1";
+
+ rr = new ResourceRequest();
+ rr.endPointPosition = "VPE-Core2";
+ status = resourceAllocator.release(sd, rr);
+ Assert.assertTrue(status == AllocationStatus.Success);
+
+ resource.print();
+ 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"));
+ }
+
+ @Test
+ public void test014() throws Exception {
+ String t = "014";
+ log.info("============== reserve " + t + " ================================");
+ log.info("=== Test range-next-in-sequence = true - no previously reserved numbers");
+
+ String entityId = "reserve" + t;
+ String targetId = "port-id-1";
+ String resourceName = "vlan-id-filter";
+
+ String assetId = "Site::" + targetId;
+
+ dataSetup.cleanup();
+
+ 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", "1002"));
+ }
+}
diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestResourceLockNode.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestResourceLockNode.java
new file mode 100644
index 000000000..dc0761c20
--- /dev/null
+++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestResourceLockNode.java
@@ -0,0 +1,39 @@
+package jtest.org.onap.ccsdk.sli.adaptors.ra;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.MethodSorters;
+import org.onap.ccsdk.sli.adaptors.ra.ResourceLockNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath:test-context.xml" })
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestResourceLockNode {
+
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory.getLogger(TestResourceLockNode.class);
+
+ @Autowired
+ private ResourceLockNode resourceLockNode;
+
+ @Test
+ public void test1() throws Exception {
+ Map<String, String> paramMap = new HashMap<>();
+ paramMap.put("resource-name", "test-resource-1");
+ paramMap.put("lock-requester", "SDNA");
+
+ resourceLockNode.lockResource(paramMap, null);
+ resourceLockNode.unlockResource(paramMap, null);
+ Assert.assertNotNull(paramMap);
+ }
+}
diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/rm/util/LabelUtilTest.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/rm/util/LabelUtilTest.java
new file mode 100644
index 000000000..eb903ecdc
--- /dev/null
+++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/rm/util/LabelUtilTest.java
@@ -0,0 +1,45 @@
+package jtest.org.onap.ccsdk.sli.adaptors.rm.util;
+
+import org.junit.Test;
+import org.onap.ccsdk.sli.adaptors.rm.data.AllocationItem;
+import org.onap.ccsdk.sli.adaptors.rm.data.LabelAllocationRequest;
+import org.onap.ccsdk.sli.adaptors.rm.data.LabelResource;
+import org.onap.ccsdk.sli.adaptors.rm.util.LabelUtil;
+
+import java.util.Date;
+
+import static org.junit.Assert.*;
+
+public class LabelUtilTest {
+
+ @Test
+ public void testLabelUtils() {
+ LabelAllocationRequest req = new LabelAllocationRequest();
+ req.check = true;
+ req.allocate = true;
+ req.label = "testLabel";
+ req.resourceUnionId = "123";
+ req.applicationId = "testApp";
+ req.assetId = "asset1";
+ req.resourceName = "resource1";
+ req.resourceSetId = "set1";
+
+
+
+ LabelResource resource = new LabelResource();
+ resource.label = "testLabel";
+
+ LabelUtil.allocateLabel(resource, req);
+ LabelUtil.checkLabel(resource, req);
+ LabelUtil.recalculate(resource);
+
+
+
+
+
+
+
+ }
+
+
+} \ No newline at end of file
diff --git a/resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestDb.java b/resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestDb.java
new file mode 100644
index 000000000..6446240dc
--- /dev/null
+++ b/resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestDb.java
@@ -0,0 +1,37 @@
+/*-
+ * ============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.util.org.onap.ccsdk.sli.adaptors.ra;
+
+import org.springframework.jdbc.core.JdbcTemplate;
+
+public class TestDb {
+
+ private JdbcTemplate jdbcTemplate;
+
+ public TestTable table(String tableName, String idName, String... columnList) {
+ return new TestTable(jdbcTemplate, tableName, idName, columnList);
+ }
+
+ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
+ this.jdbcTemplate = jdbcTemplate;
+ }
+}
diff --git a/resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestTable.java b/resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestTable.java
new file mode 100644
index 000000000..e2541f393
--- /dev/null
+++ b/resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestTable.java
@@ -0,0 +1,135 @@
+/*-
+ * ============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.util.org.onap.ccsdk.sli.adaptors.ra;
+
+import java.sql.ResultSetMetaData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.support.rowset.SqlRowSet;
+
+public class TestTable {
+
+ private String tableName;
+ private String[] columnList;
+ private String idName;
+
+ private String insertSql;
+
+ private JdbcTemplate jdbcTemplate;
+
+ private static final Logger log = LoggerFactory.getLogger(TestTable.class);
+
+ public TestTable(JdbcTemplate jdbcTemplate, String tableName, String idName, String... columnList) {
+ this.jdbcTemplate = jdbcTemplate;
+ this.tableName = tableName;
+ this.idName = idName;
+ this.columnList = columnList;
+ createInsertSql();
+ }
+
+ public TestTable(JdbcTemplate jdbcTemplate, String tableName) {
+ this.jdbcTemplate = jdbcTemplate;
+ this.tableName = tableName;
+ }
+
+ private void createInsertSql() {
+ StringBuilder ss = new StringBuilder();
+ ss.append("INSERT INTO ").append(tableName).append(" (");
+ for (String s : columnList)
+ ss.append(s).append(", ");
+ ss.setLength(ss.length() - 2);
+ ss.append(") VALUES (");
+ for (int i = 0; i < columnList.length; i++)
+ ss.append("?, ");
+ ss.setLength(ss.length() - 2);
+ ss.append(")");
+ insertSql = ss.toString();
+ }
+
+ public void add(Object... values) {
+ jdbcTemplate.update(insertSql, values);
+ }
+
+ public void update(String updateSql, Object... values) {
+ jdbcTemplate.update(updateSql, values);
+ }
+
+ public long getLastId() {
+ return jdbcTemplate.queryForObject("SELECT max(" + idName + ") FROM " + tableName, Long.class);
+ }
+
+ public Long getId(String where) {
+ String selectSql = "SELECT " + idName + " FROM " + tableName + " WHERE " + where;
+ SqlRowSet rs = jdbcTemplate.queryForRowSet(selectSql);
+ if (rs.first())
+ return rs.getLong(idName);
+ return null;
+ }
+
+ public Object getColumn(String columnName, String where) {
+ String selectSql = "SELECT " + columnName + " FROM " + tableName + " WHERE " + where;
+ SqlRowSet rs = jdbcTemplate.queryForRowSet(selectSql);
+ if (rs.first())
+ return rs.getObject(columnName);
+ return null;
+ }
+
+ public boolean exists(String where) {
+ String selectSql = "SELECT * FROM " + tableName + " WHERE " + where;
+ SqlRowSet rs = jdbcTemplate.queryForRowSet(selectSql);
+ return rs.first();
+ }
+
+ public void delete(String where) {
+ jdbcTemplate.update("DELETE FROM " + tableName + " WHERE " + where);
+ }
+
+ public void print() {
+
+ jdbcTemplate.query("SELECT * FROM " + tableName,
+ (rs, rowNum) -> {
+ String row = "Table Data for " + tableName +"\n";
+ String col = "";
+
+ final ResultSetMetaData meta = rs.getMetaData();
+ final int columnCount = meta.getColumnCount();
+
+ do {
+ col = "";
+
+ for (int column = 1; column <= columnCount; ++column) {
+ Object obj = rs.getObject(column);
+ if(!rs.wasNull()) {
+ col = col + obj + ",";
+ }
+ }
+ col = col.trim().length() == 0 ? "" : (col.trim().substring(0, col.trim().length() - 1));
+ row = row + col + "\n";
+ } while (rs.next());
+
+ return row;
+ }).forEach(row -> {
+ log.info(row);
+ });
+ }
+} \ No newline at end of file
diff --git a/resource-assignment/provider/src/test/resources/log4j.properties b/resource-assignment/provider/src/test/resources/log4j.properties
new file mode 100644
index 000000000..34dcdfb68
--- /dev/null
+++ b/resource-assignment/provider/src/test/resources/log4j.properties
@@ -0,0 +1,26 @@
+###
+# ============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=========================================================
+###
+
+log4j.rootLogger=INFO, A1
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%d{ISO8601} %5p %t %X{UUID} %c{3}:%L - %m%n
+log4j.logger.org.hibernate=INFO
diff --git a/resource-assignment/provider/src/test/resources/sql/data.sql b/resource-assignment/provider/src/test/resources/sql/data.sql
new file mode 100644
index 000000000..236a16d18
--- /dev/null
+++ b/resource-assignment/provider/src/test/resources/sql/data.sql
@@ -0,0 +1,180 @@
+---
+-- ============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=========================================================
+---
+
+INSERT INTO RESOURCE_RULE (
+ resource_name, service_model, end_point_position, service_expression, equipment_level, equipment_expression,
+ allocation_expression, soft_limit_expression, hard_limit_expression)
+VALUES (
+ 'Bandwidth', 'L3SDN', 'IPAG-TOA', 'true', 'Port', 'true',
+ 'service-speed-kbps', '0.5 * max-port-speed', '0.9 * max-port-speed');
+
+INSERT INTO RESOURCE_RULE (
+ resource_name, service_model, end_point_position, service_expression, equipment_level, equipment_expression,
+ allocation_expression, soft_limit_expression, hard_limit_expression)
+VALUES (
+ 'Bandwidth', 'L3SDN', 'VCE-Cust', 'true', 'Server', 'true',
+ 'service-speed-kbps', '0.6 * max-server-speed * number-primary-servers', 'max-server-speed * number-primary-servers');
+
+INSERT INTO RESOURCE_RULE (
+ resource_name, service_model, end_point_position, service_expression, equipment_level,
+ equipment_expression, allocation_expression, soft_limit_expression, hard_limit_expression)
+VALUES (
+ 'Connection', 'L3SDN', 'VCE-Cust', 'true', 'Server',
+ 'true', '1', '40', '40');
+
+INSERT INTO RESOURCE_RULE (
+ resource_name, service_model, end_point_position, service_expression, equipment_level, equipment_expression,
+ allocation_expression, soft_limit_expression, hard_limit_expression)
+VALUES (
+ 'Bandwidth', 'L3SDN', 'VPE-Cust', 'true', 'Port', 'true',
+ 'service-speed-kbps', '0.5 * max-port-speed', '0.9 * max-port-speed');
+
+INSERT INTO RESOURCE_RULE (
+ resource_name, service_model, end_point_position, service_expression,
+ equipment_level, equipment_expression, allocation_expression, soft_limit_expression, hard_limit_expression)
+VALUES (
+ 'Bandwidth', 'L3AVPN-EVC', 'VPE-Cust', 'true', 'Port', 'true', 'service-speed-kbps', '8000000', '8000000');
+
+INSERT INTO RESOURCE_RULE (
+ resource_name, service_model, end_point_position, service_expression,
+ equipment_level, equipment_expression, allocation_expression, soft_limit_expression, hard_limit_expression)
+VALUES (
+ 'Connection', 'L3AVPN-EVC', 'VPE-Cust', 'true', 'Port', 'true', '1', '200', '200');
+
+INSERT INTO RESOURCE_RULE (
+ resource_name, service_model, end_point_position, service_expression,
+ equipment_level, equipment_expression, allocation_expression, soft_limit_expression, hard_limit_expression)
+VALUES (
+ 'Bandwidth', 'L3AVPN-PORT', 'VPE-Cust', 'true', 'Port', 'true', 'service-speed-kbps', '8000000', '8000000');
+
+insert into RESOURCE_THRESHOLD (
+ resource_rule_id, threshold_expression, threshold_message)
+values (
+ (select resource_rule_id from RESOURCE_RULE where resource_name = 'Bandwidth' and equipment_level = 'Server'),
+ '0.5 * max-server-speed * number-primary-servers',
+ 'The provisioned access bandwidth is at or exceeds 50% of the total server capacity.');
+
+insert into RESOURCE_THRESHOLD (
+ resource_rule_id, threshold_expression, threshold_message)
+values (
+ (select resource_rule_id from RESOURCE_RULE where resource_name = 'Bandwidth' and equipment_level = 'Server'),
+ '0.7 * max-server-speed * number-primary-servers',
+ 'The provisioned access bandwidth is at or exceeds 70% of the total server capacity.');
+
+INSERT INTO RANGE_RULE (
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
+VALUES (
+ 'subinterface-id', 'L3AVPN-EVC', 'VPE-Cust', 'Port', 'true', '100-3999');
+
+INSERT INTO RANGE_RULE (
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
+VALUES (
+ 'vlan-id-inner', 'L3AVPN-EVC', 'VPE-Cust', 'Port', 'true', '2-4091');
+
+INSERT INTO RANGE_RULE (
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
+VALUES (
+ 'bundle-id', 'L3AVPN-PORT', 'VPE-Cust', 'Port', 'true', '1-99999');
+
+INSERT INTO MAX_PORT_SPEED (
+ image_file_name, end_point_position, interface_name, max_speed, unit)
+VALUES (
+ 'JUNIPER_VPE_IMAGE_FILENAME', 'VPE-Cust', 'ae0', 5000, 'Mpbs');
+
+INSERT INTO MAX_SERVER_SPEED (server_model, evc_count, max_speed, unit, description)
+VALUES ('ALL', 5, 1600, 'Mbps', 'Max speed, when there are <=5 EVC on server');
+
+INSERT INTO MAX_SERVER_SPEED (server_model, evc_count, max_speed, unit, description)
+VALUES ('ALL', 10, 1400, 'Mbps', 'Max speed, when there are 6 to 10 (including 10) EVC on server');
+
+INSERT INTO MAX_SERVER_SPEED (server_model, evc_count, max_speed, unit, description)
+VALUES ('ALL', 15, 1000, 'Mbps', 'Max speed, when there are 11 to 15 (including 15) EVC on server');
+
+INSERT INTO MAX_SERVER_SPEED (server_model, evc_count, max_speed, unit, description)
+VALUES ('ALL', 20, 700, 'Mbps', 'Max speed, when there are 16 to 20 (including 20) EVC on server');
+
+INSERT INTO MAX_SERVER_SPEED (server_model, evc_count, max_speed, unit, description)
+VALUES ('ALL', 10000, 500, 'Mbps', 'Max speed, when there are 21 or more EVC on server');
+
+INSERT INTO PARAMETERS (name, value, category, memo)
+VALUES ('homing.pserver.sparing.ratio', '1:1', 'homing',
+ 'Ratio of primary to backup servers within any of the AIC sites. Used in RA to calculate the max allowed bw in an AIC site.');
+
+INSERT INTO RESOURCE_RULE (
+ resource_name, service_model, end_point_position, service_expression, equipment_level, equipment_expression,
+ allocation_expression, soft_limit_expression, hard_limit_expression)
+VALUES (
+ 'PortBandwidth', 'ADIG', 'VPE', 'true', 'Port', 'true',
+ 'service-speed-mbps', 'service-speed-mbps', 'service-speed-mbps');
+
+INSERT INTO RESOURCE_RULE (
+ resource_name, service_model, end_point_position, service_expression, equipment_level, equipment_expression,
+ allocation_expression, soft_limit_expression, hard_limit_expression)
+VALUES (
+ 'Bandwidth', 'ADIG', 'VPE', 'true', 'VNF', 'vnf-type = "VPE"',
+ 'service-speed-mbps', '0.5 * max-vpe-bandwidth-mbps', '0.9 * max-vpe-bandwidth-mbps');
+
+
+INSERT INTO RESOURCE_RULE (
+ resource_name, service_model, end_point_position, service_expression, equipment_level, equipment_expression,
+ allocation_expression, soft_limit_expression, hard_limit_expression)
+VALUES (
+ 'Bandwidth', 'ADIG', 'VPE', 'true', 'AffinityLink', 'true',
+ 'service-speed-mbps', '9999999999', '9999999999');
+
+INSERT INTO RESOURCE_RULE (
+ resource_name, service_model, end_point_position, service_expression, equipment_level, equipment_expression,
+ allocation_expression, soft_limit_expression, hard_limit_expression)
+VALUES (
+ 'Connection', 'ADIG', 'VPE', 'true', 'VNF', 'true',
+ '1', '200', '200');
+
+INSERT INTO RANGE_RULE (
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
+VALUES (
+ 'cust-vlan-id', 'ADIG', 'VPE', 'VNF', 'true', '2-1000');
+
+INSERT INTO RANGE_RULE (
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
+VALUES (
+ 'vlan-id-inner', 'ADIG', 'VPE', 'VNF', 'true', '1002-2000');
+
+
+INSERT INTO RANGE_RULE (
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
+VALUES (
+ 'vlan-id-outer', 'MY-SERV-MODEL', 'VPE-Cust', 'Site', 'true', '2-1000');
+
+INSERT INTO RANGE_RULE (
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
+VALUES (
+ 'vlan-id-filter', 'MY-SERV-MODEL', 'VPE-Core1', 'Site', 'true', '1002-2000');
+
+INSERT INTO RANGE_RULE (
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
+VALUES (
+ 'vlan-id-filter', 'MY-SERV-MODEL', 'VPE-Core2', 'Site', 'true', '1002-2000,2200-4000');
+
+INSERT INTO RANGE_RULE (
+ range_name, service_model, end_point_position, equipment_level, equipment_expression, ranges)
+VALUES (
+ 'vlan-id-filter', 'MY-SERV-MODEL', 'VPE-Core3', 'Site', 'true', '400-600');
+ \ No newline at end of file
diff --git a/resource-assignment/provider/src/test/resources/sql/schema.sql b/resource-assignment/provider/src/test/resources/sql/schema.sql
new file mode 100644
index 000000000..275337e44
--- /dev/null
+++ b/resource-assignment/provider/src/test/resources/sql/schema.sql
@@ -0,0 +1,201 @@
+---
+-- ============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=========================================================
+---
+
+CREATE TABLE RESOURCE_LOCK (
+ resource_lock_id SERIAL PRIMARY KEY,
+ resource_name VARCHAR(50) NOT NULL UNIQUE,
+ lock_holder VARCHAR(100) NOT NULL,
+ lock_count SMALLINT NOT NULL,
+ lock_time DATETIME NOT NULL,
+ expiration_time DATETIME NOT NULL
+);
+
+CREATE TABLE RESOURCE (
+ resource_id SERIAL PRIMARY KEY,
+ asset_id VARCHAR(50) NOT NULL,
+ resource_name VARCHAR(50) NOT NULL,
+ resource_type VARCHAR(10) NOT NULL,
+ lt_used BIGINT,
+ ll_label VARCHAR(50),
+ ll_reference_count SMALLINT,
+ rr_used VARCHAR(4000)
+);
+
+ALTER TABLE RESOURCE ADD CONSTRAINT c1_resource CHECK (resource_type IN ('Limit', 'Label', 'Range'));
+CREATE UNIQUE INDEX ak1_resource ON RESOURCE (asset_id, resource_name);
+
+CREATE TABLE RESOURCE_LOAD (
+ resource_load_id SERIAL PRIMARY KEY,
+ resource_id BIGINT NOT NULL REFERENCES resource (resource_id),
+ application_id VARCHAR(20) NOT NULL,
+ resource_load_time DATETIME NOT NULL,
+ resource_expiration_time DATETIME
+);
+
+CREATE INDEX i1_resource_load ON RESOURCE_LOAD (resource_id);
+CREATE UNIQUE INDEX ak1_resource_load ON RESOURCE_LOAD (resource_id, application_id);
+
+CREATE TABLE ALLOCATION_ITEM (
+ allocation_item_id SERIAL PRIMARY KEY,
+ resource_id BIGINT NOT NULL REFERENCES resource (resource_id),
+ application_id VARCHAR(50) NOT NULL,
+ resource_set_id VARCHAR(50) NOT NULL,
+ resource_union_id VARCHAR(50) NOT NULL,
+ resource_share_group_list VARCHAR(200),
+ lt_used BIGINT,
+ ll_label VARCHAR(50),
+ rr_used VARCHAR(200),
+ allocation_time DATETIME NOT NULL
+);
+
+CREATE INDEX i1_allocation_item ON allocation_item (resource_id);
+CREATE UNIQUE INDEX ak1_allocation_item ON allocation_item (resource_id, resource_set_id);
+
+CREATE TABLE RESOURCE_RULE (
+ resource_rule_id SERIAL PRIMARY KEY,
+ resource_name VARCHAR(50) NOT NULL,
+ service_model VARCHAR(50) NOT NULL,
+ end_point_position VARCHAR(50) NOT NULL,
+ service_expression VARCHAR(2000) NOT NULL,
+ equipment_level VARCHAR(50) NOT NULL,
+ equipment_expression VARCHAR(2000) NOT NULL,
+ allocation_expression VARCHAR(2000) NOT NULL,
+ soft_limit_expression VARCHAR(2000) NOT NULL,
+ hard_limit_expression VARCHAR(2000) NOT NULL
+);
+
+CREATE TABLE RESOURCE_THRESHOLD (
+ resource_threshold_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
+ resource_rule_id bigint(20) NOT NULL,
+ threshold_expression varchar(2000) NOT NULL,
+ threshold_message varchar(2000) NOT NULL,
+ PRIMARY KEY (resource_threshold_id)
+);
+
+CREATE TABLE RANGE_RULE (
+ range_rule_id SERIAL PRIMARY KEY,
+ range_name VARCHAR(50) NOT NULL,
+ service_model VARCHAR(50) NOT NULL,
+ end_point_position VARCHAR(50) NOT NULL,
+ equipment_level VARCHAR(50) NOT NULL,
+ equipment_expression VARCHAR(2000) NOT NULL,
+ ranges VARCHAR(100) NOT NULL
+);
+
+CREATE TABLE MAX_PORT_SPEED (
+ max_port_speed_id SERIAL PRIMARY KEY,
+ image_file_name VARCHAR(50) NOT NULL,
+ end_point_position VARCHAR(50) NOT NULL,
+ interface_name VARCHAR(100) NOT NULL,
+ max_speed BIGINT NOT NULL,
+ unit VARCHAR(10) NOT NULL
+);
+
+CREATE TABLE MAX_SERVER_SPEED (
+ max_server_speed_id SERIAL PRIMARY KEY,
+ server_model VARCHAR(50) NOT NULL,
+ evc_count SMALLINT NOT NULL,
+ max_speed BIGINT NOT NULL,
+ unit VARCHAR(10) NOT NULL,
+ description VARCHAR(500)
+);
+
+CREATE TABLE SERVICE_RESOURCE (
+ service_resource_id SERIAL PRIMARY KEY,
+ service_instance_id VARCHAR(80) NOT NULL,
+ service_status VARCHAR(10) NOT NULL,
+ service_change_number SMALLINT NOT NULL,
+ resource_set_id VARCHAR(100) NOT NULL,
+ resource_union_id VARCHAR(100) NOT NULL
+);
+
+ALTER TABLE SERVICE_RESOURCE ADD CONSTRAINT C1_SERVICE_RESOURCE CHECK (service_status IN ('Active', 'Pending'));
+CREATE INDEX i1_service_resource ON SERVICE_RESOURCE (service_instance_id);
+CREATE UNIQUE INDEX ak1_service_resource ON SERVICE_RESOURCE (service_instance_id, service_change_number);
+
+CREATE TABLE VPE_POOL (
+ vpe_name VARCHAR(20) NOT NULL,
+ ipv4_oam_address VARCHAR(20) NOT NULL,
+ loopback0_ipv4_address VARCHAR(20) NOT NULL,
+ provisioning_status VARCHAR(10) NOT NULL,
+ aic_site_id VARCHAR(100) NOT NULL,
+ availability_zone VARCHAR(100) NOT NULL,
+ vlan_id_outer VARCHAR(20) NOT NULL,
+ vendor VARCHAR(20) NOT NULL,
+ physical_intf_name VARCHAR(40) NOT NULL,
+ physical_intf_speed VARCHAR(20) NOT NULL,
+ physical_intf_units VARCHAR(20) NOT NULL,
+ vpe_uuid VARCHAR(80) DEFAULT NULL,
+ vpe_id VARCHAR(80) DEFAULT NULL,
+ image_filename VARCHAR(100) DEFAULT NULL,
+ PRIMARY KEY (aic_site_id, vpe_name, availability_zone)
+);
+
+CREATE TABLE VPLSPE_POOL (
+ vplspe_name varchar(20) NOT NULL,
+ aic_site_id varchar(100) NOT NULL,
+ availability_zone varchar(100) NOT NULL,
+ physical_intf_name varchar(40) NOT NULL,
+ physical_intf_speed varchar(20) NOT NULL,
+ physical_intf_units varchar(20) NOT NULL,
+ loopback0_ipv4_address varchar(20) NOT NULL,
+ vlan_id_outer varchar(20) NOT NULL,
+ vplspe_uuid varchar(80) DEFAULT NULL,
+ image_filename varchar(100) DEFAULT NULL,
+ provisioning_status varchar(10) DEFAULT NULL,
+ vendor varchar(20) DEFAULT NULL,
+ PRIMARY KEY (vplspe_name, aic_site_id, availability_zone, physical_intf_name)
+);
+
+CREATE TABLE VPE_LOCK (
+ vpe_name varchar(20) NOT NULL,
+ vpn_lock varchar(20) NOT NULL,
+ PRIMARY KEY (vpe_name)
+);
+
+CREATE TABLE PARAMETERS (
+ name varchar(100) PRIMARY KEY,
+ value varchar(24) NOT NULL,
+ category varchar(24) NOT NULL,
+ memo varchar(128)
+);
+
+CREATE TABLE PSERVER (
+ hostname varchar(255) NOT NULL,
+ ptnii_equip_name varchar(255),
+ number_of_cpus varchar(255),
+ disk_in_gigabytes varchar(255),
+ ram_in_megabytes varchar(255),
+ equip_type varchar(255),
+ equip_vendor varchar(255),
+ equip_model varchar(255),
+ fqdn varchar(255),
+ pserver_selflink varchar(255),
+ ipv4_oam_address varchar(15),
+ serial_number varchar(255),
+ pserver_id varchar(255),
+ internet_topology varchar(40),
+ aic_site_id varchar(100),
+ in_maint varchar(5),
+ pserver_name2 varchar(255),
+ purpose varchar(255),
+ PRIMARY KEY (hostname)
+);
diff --git a/resource-assignment/provider/src/test/resources/test-context.xml b/resource-assignment/provider/src/test/resources/test-context.xml
new file mode 100644
index 000000000..ecebec723
--- /dev/null
+++ b/resource-assignment/provider/src/test/resources/test-context.xml
@@ -0,0 +1,153 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ============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=========================================================
+ -->
+
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:jdbc="http://www.springframework.org/schema/jdbc"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
+ http://www.springframework.org/schema/jdbc
+ http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.1.xsd
+ ">
+
+ <context:annotation-config />
+
+ <!-- JDBC setup -->
+
+ <bean id="test.dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"
+ lazy-init="false" primary="true">
+ <property name="driverClassName" value="org.h2.Driver" />
+ <property name="url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;MODE=MySQL" />
+ </bean>
+
+ <jdbc:initialize-database data-source="test.dataSource">
+ <jdbc:script location="sql/schema.sql" />
+ <jdbc:script location="sql/data.sql" />
+ </jdbc:initialize-database>
+
+ <bean id="lock.dataSource" class="org.onap.ccsdk.sli.adaptors.util.db.CachedDataSourceWrap">
+ <property name="dataSource" ref="test.dataSource" />
+ </bean>
+
+ <bean id="rm.jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" primary="true">
+ <property name="dataSource" ref="test.dataSource" />
+ </bean>
+
+ <bean id="lock.jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
+ <property name="dataSource" ref="lock.dataSource" />
+ </bean>
+
+ <bean id="testDb" class="jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestDb">
+ <property name="jdbcTemplate" ref="rm.jdbcTemplate" />
+ </bean>
+
+ <bean id="dataSetup" class="jtest.org.onap.ccsdk.sli.adaptors.ra.DataSetup">
+ <property name="testDb" ref="testDb" />
+ </bean>
+
+ <!-- Resource Lock Configuration -->
+
+ <bean id="resourceLockDao" class="org.onap.ccsdk.sli.adaptors.lock.dao.ResourceLockDaoImpl">
+ <property name="jdbcTemplate" ref="lock.jdbcTemplate" />
+ </bean>
+
+ <bean id="lockHelper" class="org.onap.ccsdk.sli.adaptors.lock.comp.LockHelperImpl">
+ <property name="resourceLockDao" ref="resourceLockDao" />
+ <property name="retryCount" value="10" />
+ <property name="lockWait" value="5" /> <!-- Seconds -->
+ </bean>
+
+ <!-- RM Configuration -->
+
+ <bean id="resourceJdbcDao" class="org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceJdbcDaoImpl">
+ <property name="jdbcTemplate" ref="rm.jdbcTemplate" />
+ </bean>
+
+ <bean id="allocationItemJdbcDao" class="org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.AllocationItemJdbcDaoImpl">
+ <property name="jdbcTemplate" ref="rm.jdbcTemplate" />
+ </bean>
+
+ <bean id="resourceLoadJdbcDao" class="org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceLoadJdbcDaoImpl">
+ <property name="jdbcTemplate" ref="rm.jdbcTemplate" />
+ </bean>
+
+ <bean id="resourceDao" class="org.onap.ccsdk.sli.adaptors.rm.dao.jdbc.ResourceDaoImpl">
+ <property name="resourceJdbcDao" ref="resourceJdbcDao" />
+ <property name="allocationItemJdbcDao" ref="allocationItemJdbcDao" />
+ <property name="resourceLoadJdbcDao" ref="resourceLoadJdbcDao" />
+ </bean>
+
+ <bean id="resourceManager" class="org.onap.ccsdk.sli.adaptors.rm.comp.ResourceManagerImpl">
+ <property name="lockHelper" ref="lockHelper" />
+ <property name="resourceDao" ref="resourceDao" />
+ <property name="lockTimeout" value="600" /> <!-- Seconds -->
+ </bean>
+
+ <!-- Rule DAO Configuration -->
+
+ <bean id="resourceRuleDao" class="org.onap.ccsdk.sli.adaptors.ra.rule.dao.ResourceRuleDaoImpl">
+ <property name="jdbcTemplate" ref="rm.jdbcTemplate" />
+ </bean>
+
+ <bean id="rangeRuleDao" class="org.onap.ccsdk.sli.adaptors.ra.rule.dao.RangeRuleDaoImpl">
+ <property name="jdbcTemplate" ref="rm.jdbcTemplate" />
+ </bean>
+
+ <!-- ResourceAllocator Configuration -->
+
+ <bean id="resourceAllocator" class="org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator">
+ <property name="resourceManager" ref="resourceManager" />
+ <property name="endPointAllocator" ref="endPointAllocator" />
+ <property name="speedUtil" ref="speedUtil" />
+ </bean>
+
+ <bean id="resourceLockNode" class="org.onap.ccsdk.sli.adaptors.ra.ResourceLockNode">
+ <property name="lockHelper" ref="lockHelper" />
+ </bean>
+
+ <bean id="speedUtil" class="org.onap.ccsdk.sli.adaptors.util.speed.SpeedUtil" />
+
+ <!-- EndPointAllocator Configuration -->
+
+ <bean id="endPointAllocator" class="org.onap.ccsdk.sli.adaptors.ra.comp.EndPointAllocatorImpl">
+ <property name="resourceManager" ref="resourceManager" />
+ <property name="allocationRuleMap">
+ <map>
+ <entry key="DEFAULT">
+ <list>
+ <ref bean="dbAllocationRule" />
+ </list>
+ </entry>
+ </map>
+ </property>
+ </bean>
+
+ <!-- Resource Allocation Rule Configuration -->
+
+ <bean id="dbAllocationRule" class="org.onap.ccsdk.sli.adaptors.ra.alloc.DbAllocationRule">
+ <property name="resourceRuleDao" ref="resourceRuleDao" />
+ <property name="rangeRuleDao" ref="rangeRuleDao" />
+ </bean>
+
+</beans>