diff options
Diffstat (limited to 'resource-assignment/provider/src/main/java')
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; } |