From 3531095b169085b5cfd25c4dbc2e9be2d35314f2 Mon Sep 17 00:00:00 2001 From: sb5356 Date: Wed, 25 Mar 2020 15:48:17 -0400 Subject: RA: Add the allowed range in the return values Change-Id: I18530c17ac78269c1b48ba499edfb3921d23f164 Issue-ID: CCSDK-2189 Signed-off-by: Stan Bonev --- .../ccsdk/sli/adaptors/ra/ResourceAllocator.java | 43 +++++++++++++++++++--- .../adaptors/ra/comp/EndPointAllocatorImpl.java | 17 ++++++++- .../ccsdk/sli/adaptors/ra/comp/ResourceData.java | 2 +- .../onap/ccsdk/sli/adaptors/ra/TestReserve.java | 11 ++++++ 4 files changed, 65 insertions(+), 8 deletions(-) (limited to 'resource-assignment') 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 338c528a..19062d53 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 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 dataToProperties(Map data) { + if (data == null || data.isEmpty()) { + return Collections.emptyMap(); + } + + Map prop = new HashMap<>(); + Map 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 mm = (Map) o; + for (String key1 : mm.keySet()) { + data1.put(key + "." + key1, mm.get(key1)); + } + } else if (o instanceof List) { + List ll = (List) 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 91f58734..36e40d58 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 rangeList = ((RangeAllocationRequest) rao.request).rangeList; + if (rangeList != null && !rangeList.isEmpty()) { + List ll = new ArrayList<>(); + for (Range r : rangeList) { + Map 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 a20c01d7..d83d4cdb 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 data; + public Map data; public List allocationDataList; } diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java index 168bdd72..f42ef9c3 100644 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java +++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java @@ -634,6 +634,17 @@ public class TestReserve { 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 -- cgit 1.2.3-korg