aboutsummaryrefslogtreecommitdiffstats
path: root/resource-assignment/provider/src
diff options
context:
space:
mode:
Diffstat (limited to 'resource-assignment/provider/src')
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java32
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/AllocationData.java11
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java132
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceData.java4
-rw-r--r--resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java42
5 files changed, 161 insertions, 60 deletions
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java
index 944429a3..c51b0384 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java
@@ -28,6 +28,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.onap.ccsdk.sli.adaptors.ra.comp.AllocationData;
import org.onap.ccsdk.sli.adaptors.ra.comp.EndPointAllocator;
import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceData;
import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceEntity;
@@ -124,7 +125,9 @@ public class ResourceAllocator implements SvcLogicResource {
} else if (resourceTargetId != null && resourceTargetType != null && resourceName != null) {
ResourceData rd = endPointAllocator.getResource(resourceTargetType, resourceTargetId, resourceName,
resourceEntityTypeFilter, resourceEntityIdFilter, resourceShareGroupFilter);
- setResourceDataInContext(ctx, prefix, Collections.singletonList(rd));
+ if (rd != null) {
+ setResourceDataInContext(ctx, prefix, Collections.singletonList(rd));
+ }
} else if ((resourceTargetTypeFilter != null || resourceTargetIdFilter != null) && resourceName != null) {
List<ResourceData> rdlist = endPointAllocator.getResourcesForTarget(resourceTargetTypeFilter,
resourceTargetIdFilter, resourceName);
@@ -157,6 +160,10 @@ public class ResourceAllocator implements SvcLogicResource {
}
private void setResourceDataInContext(SvcLogicContext ctx, String prefix, List<ResourceData> rdlist) {
+ if (rdlist == null || rdlist.isEmpty()) {
+ return;
+ }
+
prefix = prefix == null ? "" : prefix + '.';
setAttr(ctx, prefix + "resource-list_length", String.valueOf(rdlist.size()));
@@ -170,7 +177,6 @@ public class ResourceAllocator implements SvcLogicResource {
setAttr(ctx, pp + "endpoint-position", rd.endPointPosition);
setAttr(ctx, pp + "resource-target-type", rd.resourceTargetType);
setAttr(ctx, pp + "resource-target-id", rd.resourceTargetId);
- // SDNGC-7687
setAttr(ctx, pp + "resource-target-value", rd.resourceTargetValue);
setAttr(ctx, pp + "status", rd.status);
@@ -180,6 +186,28 @@ public class ResourceAllocator implements SvcLogicResource {
setAttr(ctx, pp + kk, value);
}
}
+
+ if (rd.allocationDataList != null && !rd.allocationDataList.isEmpty()) {
+
+ setAttr(ctx, pp + "allocation-data-list_length", String.valueOf(rd.allocationDataList.size()));
+
+ for (int j = 0; j < rd.allocationDataList.size(); j++) {
+ AllocationData ad = rd.allocationDataList.get(j);
+
+ String ppp = pp + "allocation-data-list[" + j + "].";
+
+ setAttr(ctx, ppp + "resource-entity-type", ad.resourceEntityType);
+ setAttr(ctx, ppp + "resource-entity-id", ad.resourceEntityId);
+ setAttr(ctx, ppp + "resource-entity-version", ad.resourceEntityVersion);
+
+ if (ad.data != null && !ad.data.isEmpty()) {
+ for (String kk : ad.data.keySet()) {
+ String value = String.valueOf(ad.data.get(kk));
+ setAttr(ctx, ppp + kk, value);
+ }
+ }
+ }
+ }
}
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/AllocationData.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/AllocationData.java
new file mode 100644
index 00000000..3e0e6b14
--- /dev/null
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/AllocationData.java
@@ -0,0 +1,11 @@
+package org.onap.ccsdk.sli.adaptors.ra.comp;
+
+import java.util.Map;
+
+public class AllocationData {
+
+ public String resourceEntityType;
+ public String resourceEntityId;
+ public String resourceEntityVersion;
+ public Map<String, String> data;
+}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java
index d188429e..ab73dab1 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java
@@ -224,40 +224,8 @@ public class EndPointAllocatorImpl implements EndPointAllocator {
log.info("ResourceName:" + r.resourceKey.resourceName + " assetId:" + r.resourceKey.assetId);
- ResourceData rd = new ResourceData();
+ ResourceData rd = getResourceData(r);
rdlist.add(rd);
-
- rd.resourceName = r.resourceKey.resourceName;
- int i1 = r.resourceKey.assetId.indexOf("::");
- if (i1 > 0) {
- rd.resourceTargetType = r.resourceKey.assetId.substring(0, i1);
- rd.resourceTargetId = r.resourceKey.assetId.substring(i1 + 2);
-
- int i2 = r.resourceKey.assetId.lastIndexOf("::");
- if (i2 > i1) {
- rd.resourceTargetValue = r.resourceKey.assetId.substring(i2 + 2);
- }
- } else {
- rd.resourceTargetType = "";
- rd.resourceTargetId = r.resourceKey.assetId;
- }
-
- rd.data = new HashMap<>();
-
- if (r instanceof RangeResource) {
- RangeResource rr = (RangeResource) r;
-
- log.info("rr.used: " + rr.used);
- String ss = String.valueOf(rr.used);
- ss = ss.substring(1, ss.length() - 1);
- rd.data.put("allocated", ss);
-
- } else if (r instanceof LimitResource) {
- LimitResource lr = (LimitResource) r;
-
- log.info("lr.used: " + lr.used);
- rd.data.put("allocated", String.valueOf(lr.used));
- }
}
return rdlist;
@@ -266,7 +234,6 @@ public class EndPointAllocatorImpl implements EndPointAllocator {
@Override
public ResourceData getResource(String resourceTargetType, String resourceTargetId, String resourceName,
String resourceEntityTypeFilter, String resourceEntityIdFilter, String resourceShareGroupFilter) {
- ResourceData rd = new ResourceData();
String assetId = resourceTargetType + "::" + resourceTargetId;
String resourceUnionFilter = null;
@@ -288,36 +255,87 @@ public class EndPointAllocatorImpl implements EndPointAllocator {
if (r != null) {
log.info("ResourceName:" + r.resourceKey.resourceName + " assetId:" + r.resourceKey.assetId);
- rd.resourceName = r.resourceKey.resourceName;
- int i1 = r.resourceKey.assetId.indexOf("::");
- if (i1 > 0) {
- rd.resourceTargetType = r.resourceKey.assetId.substring(0, i1);
- rd.resourceTargetId = r.resourceKey.assetId.substring(i1 + 2);
+ ResourceData rd = getResourceData(r);
+ return rd;
+ }
- int i2 = r.resourceKey.assetId.lastIndexOf("::");
- if (i2 > i1) {
- rd.resourceTargetValue = r.resourceKey.assetId.substring(i2 + 2);
- }
- } else {
- rd.resourceTargetType = "";
- rd.resourceTargetId = r.resourceKey.assetId;
+ return null;
+ }
+
+ private ResourceData getResourceData(Resource r) {
+ ResourceData rd = new ResourceData();
+
+ rd.resourceName = r.resourceKey.resourceName;
+ int i1 = r.resourceKey.assetId.indexOf("::");
+ if (i1 > 0) {
+ rd.resourceTargetType = r.resourceKey.assetId.substring(0, i1);
+ rd.resourceTargetId = r.resourceKey.assetId.substring(i1 + 2);
+
+ int i2 = r.resourceKey.assetId.lastIndexOf("::");
+ if (i2 > i1) {
+ rd.resourceTargetValue = r.resourceKey.assetId.substring(i2 + 2);
}
+ } else {
+ rd.resourceTargetType = "";
+ rd.resourceTargetId = r.resourceKey.assetId;
+ }
- rd.data = new HashMap<>();
+ rd.data = new HashMap<>();
+
+ if (r instanceof RangeResource) {
+ RangeResource rr = (RangeResource) r;
+
+ log.info("rr.used: " + rr.used);
+ String ss = String.valueOf(rr.used);
+ ss = ss.substring(1, ss.length() - 1);
+ rd.data.put("allocated", ss);
+
+ } else if (r instanceof LimitResource) {
+ LimitResource lr = (LimitResource) r;
+
+ log.info("lr.used: " + lr.used);
+ rd.data.put("allocated", String.valueOf(lr.used));
+ }
+
+ rd.allocationDataList = new ArrayList<>();
+
+ if (r.allocationItems != null) {
+ for (AllocationItem ai : r.allocationItems) {
+ AllocationData ad = new AllocationData();
+ rd.allocationDataList.add(ad);
+
+ i1 = ai.resourceUnionId.indexOf("::");
+ if (i1 > 0) {
+ ad.resourceEntityType = ai.resourceUnionId.substring(0, i1);
+ ad.resourceEntityId = ai.resourceUnionId.substring(i1 + 2);
+ } else {
+ ad.resourceEntityType = "";
+ ad.resourceEntityId = ai.resourceUnionId;
+ }
- if (r instanceof RangeResource) {
- RangeResource rr = (RangeResource) r;
+ i1 = ai.resourceSetId.lastIndexOf("::");
+ if (i1 > 0) {
+ ad.resourceEntityVersion = ai.resourceSetId.substring(i1 + 2);
+ } else {
+ ad.resourceEntityVersion = "";
+ }
+
+ ad.data = new HashMap<>();
+
+ if (ai instanceof RangeAllocationItem) {
+ RangeAllocationItem rai = (RangeAllocationItem) ai;
- log.info("rr.used: " + rr.used);
- String ss = String.valueOf(rr.used);
- ss = ss.substring(1, ss.length() - 1);
- rd.data.put("allocated", ss);
+ log.info("rr.used: " + rai.used);
+ String ss = String.valueOf(rai.used);
+ ss = ss.substring(1, ss.length() - 1);
+ ad.data.put("allocated", ss);
- } else if (r instanceof LimitResource) {
- LimitResource lr = (LimitResource) r;
+ } else if (ai instanceof LimitAllocationItem) {
+ LimitAllocationItem lai = (LimitAllocationItem) ai;
- log.info("lr.used: " + lr.used);
- rd.data.put("allocated", String.valueOf(lr.used));
+ log.info("lr.used: " + lai.used);
+ ad.data.put("allocated", String.valueOf(lai.used));
+ }
}
}
diff --git a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceData.java b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceData.java
index a5881b95..a20c01d7 100644
--- a/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceData.java
+++ b/resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceData.java
@@ -21,6 +21,7 @@
package org.onap.ccsdk.sli.adaptors.ra.comp;
+import java.util.List;
import java.util.Map;
public class ResourceData {
@@ -29,7 +30,8 @@ public class ResourceData {
public String resourceTargetId;
public String resourceTargetValue;
public String resourceTargetType;
+ public String endPointPosition;
public String status;
public Map<String, String> data;
- public String endPointPosition;
+ public List<AllocationData> allocationDataList;
}
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
index 4be985b2..f31a3859 100644
--- 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
@@ -85,6 +85,27 @@ public class TestQueryResource {
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
@@ -111,5 +132,26 @@ public class TestQueryResource {
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");
}
}