From f4bf9e7ad4746fbec415c0ad34fa57f168840e30 Mon Sep 17 00:00:00 2001 From: sarada prasad sahoo Date: Fri, 7 Jun 2019 14:46:36 +0530 Subject: Enhanced List Level flow with backward support Modified the e2e service instance flow to support both new list types groups along with backward compatibility to support old types alloted resources, network etc. Change-Id: Ie8fc8a4550a90b44736b6b9de058e2a2e187570c Issue-ID: SO-1393 Signed-off-by: sarada prasad sahoo --- .../bpmn/common/resource/InstanceResourceList.java | 171 +++++++++------------ .../common/resource/ResourceRequestBuilder.java | 9 +- .../common/resource/InstnaceResourceListTest.java | 76 ++++++++- .../InstanceResourceList/InstanceResourceList.json | 26 ++++ 4 files changed, 177 insertions(+), 105 deletions(-) (limited to 'bpmn/MSOCommonBPMN/src') diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java index 2b650e1eed..b1173bbf95 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java @@ -24,16 +24,15 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import org.onap.so.bpmn.core.domain.GroupResource; -import org.onap.so.bpmn.core.domain.Resource; -import org.onap.so.bpmn.core.domain.ResourceType; -import org.onap.so.bpmn.core.domain.VnfResource; import java.lang.reflect.Type; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import org.apache.commons.lang3.StringUtils; +import org.onap.so.bpmn.core.domain.GroupResource; +import org.onap.so.bpmn.core.domain.Resource; +import org.onap.so.bpmn.core.domain.VnfResource; public class InstanceResourceList { @@ -41,72 +40,6 @@ public class InstanceResourceList { throw new IllegalStateException("Utility class"); } - private static Map>> convertUUIReqTOStd(final JsonObject reqInputJsonObj, - List seqResourceList) { - - Map>> normalizedRequest = new HashMap<>(); - Resource lastVfProcessed = null; - for (Resource r : seqResourceList) { - - if (r.getResourceType() == ResourceType.VNF) { - String pk = getPrimaryKey(r); - - JsonElement vfNode = reqInputJsonObj.get(pk); - lastVfProcessed = r; - - // if the service property is type of array then it - // means it is a VF resource - if (vfNode instanceof JsonArray) { - - for (int i = 0; i < ((JsonArray) vfNode).size(); i++) { - List> groupsList = normalizedRequest.get(pk); - if (groupsList == null) { - groupsList = new ArrayList<>(); - normalizedRequest.put(pk, groupsList); - } - - groupsList.add(new ArrayList<>()); - } - } - - } else if (r.getResourceType() == ResourceType.GROUP) { - String sk = getPrimaryKey(r); - - // if sk is empty that means it is not list type - if (sk.isEmpty()) { - List> vfList = normalizedRequest.get(getPrimaryKey(lastVfProcessed)); - for (List grpList : vfList) { - grpList.add((GroupResource) r); - } - continue; - } - - String pk = getPrimaryKey(lastVfProcessed); - JsonArray vfs = reqInputJsonObj.getAsJsonArray(pk); - - for (int i = 0; i < vfs.size(); i++) { - - JsonElement vfcsNode = vfs.get(i).getAsJsonObject().get(sk); - if (vfcsNode instanceof JsonArray) { - - List groupResources = normalizedRequest.get(pk).get(i); - - if (groupResources == null) { - groupResources = new ArrayList<>(); - normalizedRequest.get(pk).add(i, groupResources); - } - - for (int j = 0; j < ((JsonArray) vfcsNode).size(); j++) { - groupResources.add((GroupResource) r); - } - } - } - - } - } - return normalizedRequest; - } - // this method returns key from resource input // e.g. {\"sdwansite_emails\" : \"[sdwansiteresource_list(PK), INDEX, sdwansite_emails]|default\", // ....} @@ -129,45 +62,87 @@ public class InstanceResourceList { return pkOpt.isPresent() ? pkOpt.get() : ""; } else { - // TODO: handle the case if VNF resource is not list - // e.g. { resourceInput return ""; } } - private static List convertToInstanceResourceList(Map>> normalizedReq, - List seqResourceList) { - List flatResourceList = new ArrayList<>(); - for (Resource r : seqResourceList) { - if (r.getResourceType() == ResourceType.VNF) { - String primaryKey = getPrimaryKey(r); - for (String pk : normalizedReq.keySet()) { - if (primaryKey.equalsIgnoreCase(pk)) { - - List> vfs = normalizedReq.get(pk); + public static List getInstanceResourceList(final VnfResource vnfResource, final String uuiRequest) { + List sequencedResourceList = new ArrayList(); + Gson gson = new Gson(); + JsonObject servJsonObject = gson.fromJson(uuiRequest, JsonObject.class); + JsonObject reqInputJsonObj = servJsonObject.getAsJsonObject("service").getAsJsonObject("parameters") + .getAsJsonObject("requestInputs"); - vfs.stream().forEach(e -> { - flatResourceList.add(r); - flatResourceList.addAll(e); - }); + String pk = getPrimaryKey(vnfResource); + // if pk is not empty that means it can contain list of VNF + if (!pk.isEmpty()) { + JsonElement vfNode = reqInputJsonObj.get(pk); + if (vfNode.isJsonArray()) { + // multiple instance of VNF + JsonArray vfNodeList = vfNode.getAsJsonArray(); + for (JsonElement vf : vfNodeList) { + JsonObject vfObj = vf.getAsJsonObject(); + + // Add VF first before adding groups + sequencedResourceList.add(vnfResource); + List sequencedGroupResourceList = getGroupResourceInstanceList(vnfResource, vfObj); + if (!sequencedGroupResourceList.isEmpty()) { + sequencedResourceList.addAll(sequencedGroupResourceList); } } } + } else { + // if pk is empty that means it has only one VNF Node + // Add VF first before adding groups + sequencedResourceList.add(vnfResource); + // check the groups for this VNF and add into resource list + List sequencedGroupResourceList = getGroupResourceInstanceList(vnfResource, reqInputJsonObj); + if (!sequencedGroupResourceList.isEmpty()) { + sequencedResourceList.addAll(sequencedGroupResourceList); + } } - return flatResourceList; - } - public static List getInstanceResourceList(final List seqResourceList, - final String uuiRequest) { + // In negative case consider only VNF resource only + if (sequencedResourceList.isEmpty()) { + sequencedResourceList.add(vnfResource); + } - Gson gson = new Gson(); - JsonObject servJsonObject = gson.fromJson(uuiRequest, JsonObject.class); - JsonObject reqInputJsonObj = servJsonObject.getAsJsonObject("service").getAsJsonObject("parameters") - .getAsJsonObject("requestInputs"); + return sequencedResourceList; + } - // this will convert UUI request to normalized form - Map>> normalizedRequest = convertUUIReqTOStd(reqInputJsonObj, seqResourceList); - return convertToInstanceResourceList(normalizedRequest, seqResourceList); + private static List getGroupResourceInstanceList(VnfResource vnfResource, JsonObject vfObj) { + List sequencedResourceList = new ArrayList(); + if (vnfResource.getGroupOrder() != null && !StringUtils.isEmpty(vnfResource.getGroupOrder())) { + String[] grpSequence = vnfResource.getGroupOrder().split(","); + for (String grpType : grpSequence) { + for (GroupResource gResource : vnfResource.getGroups()) { + if (StringUtils.containsIgnoreCase(gResource.getModelInfo().getModelName(), grpType)) { + // check the number of group instances from UUI to be added + String sk = getPrimaryKey(gResource); + + // if sk is empty that means it is not list type + // only one group / vnfc to be considered + if (sk.isEmpty()) { + sequencedResourceList.add(gResource); + } else { + // check the number of list size of VNFC of a group + JsonElement vfcNode = vfObj.get(sk); + if (vfcNode.isJsonArray()) { + JsonArray vfcList = vfcNode.getAsJsonArray(); + for (JsonElement vfc : vfcList) { + sequencedResourceList.add(gResource); + } + } else { + // consider only one vnfc/group if not an array + sequencedResourceList.add(gResource); + } + } + + } + } + } + } + return sequencedResourceList; } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java index faa3d74dba..b814d6c595 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java @@ -122,8 +122,13 @@ public class ResourceRequestBuilder { Map uuiRequestInputs = null; if (JsonUtils.getJsonValue(uuiServiceParameters, "requestInputs") != null) { - uuiRequestInputs = - getJsonObject((String) JsonUtils.getJsonValue(uuiServiceParameters, "requestInputs"), Map.class); + String uuiRequestInputStr = JsonUtils.getJsonValue(uuiServiceParameters, "requestInputs"); + logger.info("resource input from UUI: " + uuiRequestInputStr); + if (uuiRequestInputStr == null || uuiRequestInputStr.isEmpty()) { + uuiRequestInputStr = "{}"; + } + + uuiRequestInputs = getJsonObject(uuiRequestInputStr, Map.class); } if (uuiRequestInputs == null) { diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/InstnaceResourceListTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/InstnaceResourceListTest.java index 3be67c965c..f3233f2350 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/InstnaceResourceListTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/InstnaceResourceListTest.java @@ -3,6 +3,7 @@ package org.onap.so.bpmn.common.resource; import org.junit.Assert; import org.junit.Test; import org.onap.so.bpmn.core.domain.GroupResource; +import org.onap.so.bpmn.core.domain.ModelInfo; import org.onap.so.bpmn.core.domain.Resource; import org.onap.so.bpmn.core.domain.ResourceType; import org.onap.so.bpmn.core.domain.VnfResource; @@ -23,15 +24,67 @@ public class InstnaceResourceListTest { String uuiRequest = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "InstanceResourceList" + ".json"))); List instanceResourceList = InstanceResourceList.getInstanceResourceList(createResourceSequence(), uuiRequest); - Assert.assertEquals(4, instanceResourceList.size()); + Assert.assertEquals(7, instanceResourceList.size()); Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(0).getResourceType()); Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(1).getResourceType()); - Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(2).getResourceType()); + Assert.assertEquals("device", instanceResourceList.get(1).getModelInfo().getModelName()); + Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(2).getResourceType()); + Assert.assertEquals("sitewan", instanceResourceList.get(2).getModelInfo().getModelName()); Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(3).getResourceType()); + Assert.assertEquals("sitewan", instanceResourceList.get(3).getModelInfo().getModelName()); + Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(4).getResourceType()); + Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(5).getResourceType()); + Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(6).getResourceType()); } - private List createResourceSequence() { - List resourceList = new ArrayList<>(); + // Test when PK is empty + @Test + public void testSimpleVFResource() throws IOException { + String uuiRequest = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "InstanceResourceList" + ".json"))); + VnfResource vnfResource = new VnfResource(); + vnfResource.setResourceInput("{\"a\":\"ipaddress|127.0.0.1\"}"); + List instanceResourceList = InstanceResourceList.getInstanceResourceList(vnfResource, uuiRequest); + Assert.assertEquals(1, instanceResourceList.size()); + Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(0).getResourceType()); + } + + // Test when PK is not empty and PK does not contain any groups + @Test + public void testVFWithEmptyGroupResource() throws IOException { + String uuiRequest = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "InstanceResourceList" + ".json"))); + VnfResource vnfResource = new VnfResource(); + vnfResource.setResourceInput("{\"a\":\"[emptygroup_list,INDEX,name]\"}"); + List instanceResourceList = InstanceResourceList.getInstanceResourceList(vnfResource, uuiRequest); + Assert.assertEquals(1, instanceResourceList.size()); + Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(0).getResourceType()); + } + + // Test when PK is not empty and contains a group which SK is empty + @Test + public void testVFWithEmptyGroupKeyResource() throws IOException { + String uuiRequest = new String(Files.readAllBytes(Paths.get(RESOURCE_PATH + "InstanceResourceList" + ".json"))); + VnfResource vnfResource = new VnfResource(); + vnfResource.setResourceInput("{\"a\":\"[emptygroup_list,INDEX,name]\"}"); + + VnfcResource vnfcResource = new VnfcResource(); + vnfcResource.setResourceInput("{\"a\":\"test|default_value\"}"); + GroupResource groupResource = new GroupResource(); + groupResource.setVnfcs(Arrays.asList(vnfcResource)); + ModelInfo wanModel = new ModelInfo(); + wanModel.setModelName("wan"); + groupResource.setModelInfo(wanModel); + + vnfResource.setGroupOrder("wan"); + vnfResource.setGroups(Arrays.asList(groupResource)); + + List instanceResourceList = InstanceResourceList.getInstanceResourceList(vnfResource, uuiRequest); + Assert.assertEquals(2, instanceResourceList.size()); + Assert.assertEquals(ResourceType.VNF, instanceResourceList.get(0).getResourceType()); + Assert.assertEquals(ResourceType.GROUP, instanceResourceList.get(1).getResourceType()); + Assert.assertEquals("wan", instanceResourceList.get(1).getModelInfo().getModelName()); + } + + private VnfResource createResourceSequence() { VnfResource vnfResource = new VnfResource(); vnfResource.setResourceInput("{\"a\":\"[sdwansiteresource_list,INDEX,sdwansiteresource_list]\"}"); @@ -40,7 +93,20 @@ public class InstnaceResourceListTest { GroupResource groupResource = new GroupResource(); groupResource.setVnfcs(Arrays.asList(vnfcResource)); + ModelInfo wanModel = new ModelInfo(); + wanModel.setModelName("sitewan"); + groupResource.setModelInfo(wanModel); + + VnfcResource vnfcDeviceResource = new VnfcResource(); + vnfcDeviceResource.setResourceInput("{\"a\":\"[sdwandevice_list,INDEX,test]\"}"); + GroupResource groupResource2 = new GroupResource(); + groupResource2.setVnfcs(Arrays.asList(vnfcDeviceResource)); + ModelInfo deviceModel = new ModelInfo(); + deviceModel.setModelName("device"); + groupResource2.setModelInfo(deviceModel); - return Arrays.asList(vnfResource, groupResource); + vnfResource.setGroupOrder("device,sitewan"); + vnfResource.setGroups(Arrays.asList(groupResource, groupResource2)); + return vnfResource; } } diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/InstanceResourceList/InstanceResourceList.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/InstanceResourceList/InstanceResourceList.json index 0b3d9f0bbe..a111ae2646 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/InstanceResourceList/InstanceResourceList.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/InstanceResourceList/InstanceResourceList.json @@ -67,6 +67,19 @@ } ], "requestInputs":{ + "emptygroup_list": [ + { + "topology": "hub_spoke", + "name": "defaultvpn", + "role":"Hub", + "portType":"GE", + "portSwitch":"layer3-port", + "vlanId":"", + "ipAddress":"192.168.10.1", + "deviceName":"vCPE", + "portNumer":"0/0/1" + } + ], "sdwanvpnresource_list":[ { "sdwanvpn_topology":"hub_spoke", @@ -117,6 +130,19 @@ "portNumber":"0/0/0", "ipMode":"DHCP", "publicIP":"119.3.7.113" + }, + { + "providerIpAddress":"", + "portType":"GE", + "inputBandwidth":"1200", + "ipAddress":"", + "name":"10001", + "transportNetworkName":"internet", + "outputBandwidth":"10001", + "deviceName":"vCPE", + "portNumber":"0/0/0", + "ipMode":"DHCP", + "publicIP":"119.3.7.114" } ], "sdwandevice_list":[ -- cgit 1.2.3-korg