summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src/main
diff options
context:
space:
mode:
authorsarada prasad sahoo <sarada.prasad.sahoo@huawei.com>2019-06-07 14:46:36 +0530
committersarada prasad sahoo <sarada.prasad.sahoo@huawei.com>2019-07-02 11:43:28 +0530
commitf4bf9e7ad4746fbec415c0ad34fa57f168840e30 (patch)
tree8e194f0c32fc033a2025fad9a438e47cd1e8219a /bpmn/MSOCommonBPMN/src/main
parent8e42b4e3fd9c00d73d371ccdbe2147733821bb56 (diff)
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 <sarada.prasad.sahoo@huawei.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main')
-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
2 files changed, 80 insertions, 100 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) {