summaryrefslogtreecommitdiffstats
path: root/resource-assignment/provider/src/main
diff options
context:
space:
mode:
authorsb5356 <sb5356@att.com>2020-03-25 15:48:17 -0400
committersb5356 <sb5356@att.com>2020-03-26 11:05:26 -0400
commit3531095b169085b5cfd25c4dbc2e9be2d35314f2 (patch)
treeeb1bc6cecce71acbfd75fc38e7bfaa46a9312522 /resource-assignment/provider/src/main
parentefb8d62421f0f999b88f5357cde211641837eb85 (diff)
RA: Add the allowed range in the return values
Change-Id: I18530c17ac78269c1b48ba499edfb3921d23f164 Issue-ID: CCSDK-2189 Signed-off-by: Stan Bonev <sb5356@att.com>
Diffstat (limited to 'resource-assignment/provider/src/main')
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/ResourceAllocator.java43
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/EndPointAllocatorImpl.java17
-rw-r--r--resource-assignment/provider/src/main/java/org/onap/ccsdk/sli/adaptors/ra/comp/ResourceData.java2
3 files changed, 54 insertions, 8 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 338c528a8..19062d53b 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
@@ -22,6 +22,7 @@
package org.onap.ccsdk.sli.adaptors.ra;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -180,11 +181,10 @@ public class ResourceAllocator implements SvcLogicResource {
setAttr(ctx, pp + "resource-target-value", rd.resourceTargetValue);
setAttr(ctx, pp + "status", rd.status);
- if (rd.data != null && !rd.data.isEmpty()) {
- for (String kk : rd.data.keySet()) {
- String value = String.valueOf(rd.data.get(kk));
- setAttr(ctx, pp + kk, value);
- }
+ Map<String, String> dataProp = dataToProperties(rd.data);
+ for (String kk : dataProp.keySet()) {
+ String value = String.valueOf(dataProp.get(kk));
+ setAttr(ctx, pp + kk, value);
}
if (rd.allocationDataList != null && !rd.allocationDataList.isEmpty()) {
@@ -534,6 +534,39 @@ public class ResourceAllocator implements SvcLogicResource {
return data;
}
+ @SuppressWarnings("unchecked")
+ public static Map<String, String> dataToProperties(Map<String, Object> data) {
+ if (data == null || data.isEmpty()) {
+ return Collections.emptyMap();
+ }
+
+ Map<String, String> prop = new HashMap<>();
+ Map<String, Object> data1 = new HashMap<>(data);
+
+ while (!data1.isEmpty()) {
+ for (String key : new ArrayList<>(data1.keySet())) {
+ Object o = data1.get(key);
+ data1.remove(key);
+
+ if (o instanceof Boolean || o instanceof Number || o instanceof String) {
+ prop.put(key, o.toString());
+ } else if (o instanceof Map) {
+ Map<String, Object> mm = (Map<String, Object>) o;
+ for (String key1 : mm.keySet()) {
+ data1.put(key + "." + key1, mm.get(key1));
+ }
+ } else if (o instanceof List) {
+ List<Object> ll = (List<Object>) o;
+ prop.put(key + "_length", String.valueOf(ll.size()));
+ for (int i = 0; i < ll.size(); i++) {
+ data1.put(key + '[' + i + ']', ll.get(i));
+ }
+ }
+ }
+ }
+ return prop;
+ }
+
public void setResourceManager(ResourceManager resourceManager) {
this.resourceManager = resourceManager;
}
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 91f587340..36e40d589 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
@@ -4,7 +4,7 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights
* reserved.
- *
+ *
* Modifications Copyright (C) 2019 IBM.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,8 +38,10 @@ import org.onap.ccsdk.sli.adaptors.rm.data.LimitAllocationItem;
import org.onap.ccsdk.sli.adaptors.rm.data.LimitAllocationOutcome;
import org.onap.ccsdk.sli.adaptors.rm.data.LimitResource;
import org.onap.ccsdk.sli.adaptors.rm.data.MultiResourceAllocationOutcome;
+import org.onap.ccsdk.sli.adaptors.rm.data.Range;
import org.onap.ccsdk.sli.adaptors.rm.data.RangeAllocationItem;
import org.onap.ccsdk.sli.adaptors.rm.data.RangeAllocationOutcome;
+import org.onap.ccsdk.sli.adaptors.rm.data.RangeAllocationRequest;
import org.onap.ccsdk.sli.adaptors.rm.data.RangeResource;
import org.onap.ccsdk.sli.adaptors.rm.data.ReleaseRequest;
import org.onap.ccsdk.sli.adaptors.rm.data.Resource;
@@ -129,6 +131,17 @@ public class EndPointAllocatorImpl implements EndPointAllocator {
RangeAllocationOutcome rao = (RangeAllocationOutcome) ao;
rd.data.put("allocated", String.valueOf(StrUtil.listInt(rao.allocated)));
rd.data.put("used", String.valueOf(StrUtil.listInt(rao.used)));
+ List<Range> rangeList = ((RangeAllocationRequest) rao.request).rangeList;
+ if (rangeList != null && !rangeList.isEmpty()) {
+ List<Object> ll = new ArrayList<>();
+ for (Range r : rangeList) {
+ Map<String, Object> mm = new HashMap<>();
+ mm.put("min", r.min);
+ mm.put("max", r.max);
+ ll.add(mm);
+ }
+ rd.data.put("range-list", ll);
+ }
}
return Collections.singletonList(rd);
@@ -229,7 +242,7 @@ public class EndPointAllocatorImpl implements EndPointAllocator {
log.info("ResourceName:" + r.resourceKey.resourceName + " assetId:" + r.resourceKey.assetId);
-
+
rdlist.add(getResourceData(r));
}
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 a20c01d79..d83d4cdb4 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
@@ -32,6 +32,6 @@ public class ResourceData {
public String resourceTargetType;
public String endPointPosition;
public String status;
- public Map<String, String> data;
+ public Map<String, Object> data;
public List<AllocationData> allocationDataList;
}