From be1075b1dd746bb8a7d5563ff11f985fddf3ad7f Mon Sep 17 00:00:00 2001 From: sarada prasad sahoo Date: Tue, 21 May 2019 09:58:43 +0530 Subject: Enhanced logic for multilevel list input Optimized VF/GROUP/VFC level parsing logic as per doCompareModel call flow Change-Id: If934ee1407a1bad6c9adec9e32533166b5fb4d93 Issue-ID: SO-1393 Signed-off-by: sarada prasad sahoo --- .../common/resource/ResourceRequestBuilder.java | 110 ++++++--------------- 1 file changed, 28 insertions(+), 82 deletions(-) (limited to 'bpmn/MSOCommonBPMN/src/main') 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 18a46dda99..9d0b9e42cc 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 @@ -92,7 +92,7 @@ public class ResourceRequestBuilder { * * @param execution Execution context * - * @param currentResource The current Service Resource Object + * @param resource The current Service Resource Object * * @param uuiServiceParameters the service parameters passed from the API * @@ -103,19 +103,17 @@ public class ResourceRequestBuilder { * @since ONAP Beijing Release */ @SuppressWarnings("unchecked") - public static String buildResourceRequestParameters(Execution execution, Resource currentResource, + public static String buildResourceRequestParameters(Execution execution, Resource resource, String uuiServiceParameters, Map currentVFData) { List resourceList = jsonUtil.StringArrayToList(execution, (String) JsonUtils.getJsonValue(uuiServiceParameters, "resources")); // Get the right location str for resource. default is an empty array. String locationConstraints = "[]"; - String resourceInputsFromUui = ""; - if (currentResource.getResourceType() == ResourceType.VNF) { - for (String resource : resourceList) { - String resCusUuid = (String) JsonUtils.getJsonValue(resource, "resourceCustomizationUuid"); - if ((null != resCusUuid) - && resCusUuid.equals(currentResource.getModelInfo().getModelCustomizationUuid())) { - String resourceParameters = JsonUtils.getJsonValue(resource, "parameters"); + if (resource.getResourceType() == ResourceType.VNF) { + for (String eachResource : resourceList) { + String resCusUuid = (String) JsonUtils.getJsonValue(eachResource, "resourceCustomizationUuid"); + if ((null != resCusUuid) && resCusUuid.equals(resource.getModelInfo().getModelCustomizationUuid())) { + String resourceParameters = JsonUtils.getJsonValue(eachResource, "parameters"); locationConstraints = JsonUtils.getJsonValue(resourceParameters, "locationConstraints"); } } @@ -130,25 +128,9 @@ public class ResourceRequestBuilder { if (uuiRequestInputs == null) { uuiRequestInputs = new HashMap(); } - String resourceInputStr = null; - ResourceLevel resourceLevel = null; - switch (currentResource.getResourceType()) { - case VNF: - resourceInputStr = ((VnfResource) currentResource).getResourceInput(); - resourceLevel = ResourceLevel.FIRST; - break; - case GROUP: - resourceInputStr = ((GroupResource) currentResource).getVnfcs().get(0).getResourceInput(); - resourceLevel = ResourceLevel.SECOND; - break; - } - - Map resourceInputsAfterMerge = new HashMap<>(); - if (StringUtils.isNotEmpty(resourceInputStr) && (null != resourceLevel)) { - resourceInputsAfterMerge = - getResourceInput(resourceInputStr, uuiRequestInputs, resourceLevel, currentVFData); - } + Map resourceInputsAfterMerge = + ResourceRequestBuilder.buildResouceRequest(resource, uuiRequestInputs, currentVFData); String resourceInputsStr = getJsonString(resourceInputsAfterMerge); String result = "{\n" + "\"locationConstraints\":" + locationConstraints + ",\n" + "\"requestInputs\":" @@ -157,70 +139,34 @@ public class ResourceRequestBuilder { } @SuppressWarnings("unchecked") - public static Map buildResouceRequest(String serviceUuid, String resourceCustomizationUuid, - Map serviceInputs, Map currentVFData) { + public static Map buildResouceRequest(Resource resource, Map uuiRequestInputs, + Map currentVFData) { try { - Map serviceInstnace = getServiceInstnace(serviceUuid); - // find match of customization uuid in vnf - Map> serviceResources = - (Map>) serviceInstnace.get("serviceResources"); - - List> serviceVnfCust = (List>) serviceResources.get("serviceVnfs"); - Map resourceInputData = getResourceInputStr(serviceVnfCust, resourceCustomizationUuid); - - // find match in network resource - if (resourceInputData.isEmpty()) { - List> serviceNetworkCust = - (List>) serviceResources.get("serviceNetworks"); - resourceInputData = getResourceInputStr(serviceNetworkCust, resourceCustomizationUuid); - - // find match in AR resource - if (resourceInputData.isEmpty()) { - List> serviceArCust = - (List>) serviceResources.get("serviceAllottedResources"); - resourceInputData = getResourceInputStr(serviceArCust, resourceCustomizationUuid); - } - } - String resourceInputStr = null; - ResourceLevel resourceLevel = null; - if (!resourceInputData.isEmpty()) { - resourceInputStr = resourceInputData.get("resourceInput"); - resourceLevel = ResourceLevel.valueOf(resourceInputData.get("nodeType")); + // Resource Level is considered as first level by default + ResourceLevel resourceLevel = ResourceLevel.FIRST; + switch (resource.getResourceType()) { + case VNF: + resourceInputStr = ((VnfResource) resource).getResourceInput(); + resourceLevel = ResourceLevel.FIRST; + break; + case GROUP: + resourceInputStr = ((GroupResource) resource).getVnfcs().get(0).getResourceInput(); + resourceLevel = ResourceLevel.SECOND; + break; } - if (resourceInputStr != null && !resourceInputStr.isEmpty() && resourceLevel != null) { - return getResourceInput(resourceInputStr, serviceInputs, resourceLevel, currentVFData); + Map resourceInputsAfterMerge = new HashMap<>(); + if (StringUtils.isNotEmpty(resourceInputStr)) { + return getResourceInput(resourceInputStr, uuiRequestInputs, resourceLevel, currentVFData); } } catch (Exception e) { - logger.error("not able to retrieve service instance", e); + logger.error("not able to retrieve service resource input ", e); } return new HashMap(); } - private static Map getResourceInputStr(List> resources, - String resCustomizationUuid) { - - Map resourceInputMap = new HashMap<>(2); - for (Map resource : resources) { - Map modelInfo = (Map) resource.get("modelInfo"); - - if (modelInfo.get("modelCustomizationUuid").equalsIgnoreCase(resCustomizationUuid)) { - resourceInputMap.put("resourceInput", (String) resource.get("resourceInput")); - String nodeType = ResourceLevel.FIRST.toString(); - if (((String) resource.get("resourceType")).equalsIgnoreCase("VNF")) { - nodeType = ResourceLevel.FIRST.toString(); - } else if (((String) resource.get("resourceType")).equals("GROUP")) { - nodeType = ResourceLevel.SECOND.toString(); - } - resourceInputMap.put("nodeType", nodeType); - return resourceInputMap; - } - } - return new HashMap<>(); - } - // this method combines resource input with service input private static Map getResourceInput(String resourceInputStr, Map uuiRequestInputs, ResourceLevel resourceLevel, Map currentVFData) { @@ -338,7 +284,7 @@ public class ResourceRequestBuilder { levelKeyNameUpdated = true; } - if (uuiServiceInput.containsKey(keyName)) { + if ((null != uuiServiceInput) && (uuiServiceInput.containsKey(keyName))) { Object vfcLevelObject = uuiServiceInput.get(keyName); // it will be always list if (vfcLevelObject instanceof List) { @@ -369,7 +315,7 @@ public class ResourceRequestBuilder { } else { // if not a list type - if (uuiServiceInput.containsKey(tmpKey)) { + if ((null != uuiServiceInput) && (uuiServiceInput.containsKey(tmpKey))) { value = (String) uuiServiceInput.get(tmpKey); } else { if (split.length == 1) { // means value is empty e.g. "a":"key1|" -- cgit 1.2.3-korg