summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2019-07-23 05:30:31 +0000
committerGerrit Code Review <gerrit@onap.org>2019-07-23 05:30:31 +0000
commit5184b28f6ec1170ae035ddd749d8bdf5b2064904 (patch)
tree41f5811c8b56094bb63ba1a784048ab384f4a253 /bpmn/MSOCommonBPMN/src
parentbbdb1c45a93194db2712d8c146e263a03737f25c (diff)
parentf4bf9e7ad4746fbec415c0ad34fa57f168840e30 (diff)
Merge "Enhanced List Level flow with backward support"
Diffstat (limited to 'bpmn/MSOCommonBPMN/src')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/InstanceResourceList.java171
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/resource/ResourceRequestBuilder.java9
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/resource/InstnaceResourceListTest.java76
-rw-r--r--bpmn/MSOCommonBPMN/src/test/resources/__files/InstanceResourceList/InstanceResourceList.json26
4 files changed, 177 insertions, 105 deletions
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<String, List<List<GroupResource>>> convertUUIReqTOStd(final JsonObject reqInputJsonObj,
- List<Resource> seqResourceList) {
-
- Map<String, List<List<GroupResource>>> 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<List<GroupResource>> 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<List<GroupResource>> vfList = normalizedRequest.get(getPrimaryKey(lastVfProcessed));
- for (List<GroupResource> 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<GroupResource> 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<Resource> convertToInstanceResourceList(Map<String, List<List<GroupResource>>> normalizedReq,
- List<Resource> seqResourceList) {
- List<Resource> 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<List<GroupResource>> vfs = normalizedReq.get(pk);
+ public static List<Resource> getInstanceResourceList(final VnfResource vnfResource, final String uuiRequest) {
+ List<Resource> sequencedResourceList = new ArrayList<Resource>();
+ 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<Resource> 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<Resource> sequencedGroupResourceList = getGroupResourceInstanceList(vnfResource, reqInputJsonObj);
+ if (!sequencedGroupResourceList.isEmpty()) {
+ sequencedResourceList.addAll(sequencedGroupResourceList);
+ }
}
- return flatResourceList;
- }
- public static List<Resource> getInstanceResourceList(final List<Resource> 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<String, List<List<GroupResource>>> normalizedRequest = convertUUIReqTOStd(reqInputJsonObj, seqResourceList);
- return convertToInstanceResourceList(normalizedRequest, seqResourceList);
+ private static List<Resource> getGroupResourceInstanceList(VnfResource vnfResource, JsonObject vfObj) {
+ List<Resource> sequencedResourceList = new ArrayList<Resource>();
+ 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<String, Object> 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<Resource> 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<Resource> createResourceSequence() {
- List<Resource> 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<Resource> 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<Resource> 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<Resource> 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":[