From ea65e0397e030bbd0a685f473b1c8416dd0a82f3 Mon Sep 17 00:00:00 2001 From: Aleem Raja Date: Wed, 10 Aug 2022 21:20:12 +0530 Subject: Multiple PNFs with same ModelInfo but different instance name not able to be instantiated When instantiating a service with multiple PNFs, SO differentiates them using ModelCustomizationId. This causes issues when creating multiple instances of same model resource, and each lookup would return the same object. With this patch, Instead of using ModelCustomizationId, we enable SO to use instanceName parameter to differentiate the PNFs. Issue-ID: SO-3948 Signed-off-by: Aleem Raja Change-Id: I9dd039ac786a60f7cf4d4a9c456c7681f64d6786 --- .../validation/UserParamsValidation.java | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'mso-api-handlers/mso-api-handler-infra/src/main') diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/UserParamsValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/UserParamsValidation.java index 8646a74a2f..728d4df4ee 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/UserParamsValidation.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/UserParamsValidation.java @@ -34,6 +34,7 @@ import org.onap.so.apihandlerinfra.Actions; import org.onap.so.exceptions.ValidationException; import org.onap.so.serviceinstancebeans.ModelInfo; import org.onap.so.serviceinstancebeans.Networks; +import org.onap.so.serviceinstancebeans.Pnfs; import org.onap.so.serviceinstancebeans.Service; import org.onap.so.serviceinstancebeans.VfModules; import org.onap.so.serviceinstancebeans.Vnfs; @@ -116,6 +117,29 @@ public class UserParamsValidation implements ValidationRule { validateDuplicateInstanceNames(vnfCustomIdToInstanceNames, "vnf"); validateDuplicateInstanceNames(vfModuleCustomIdToInstanceNames, "vfModule"); + Map> pnfCustomIdToInstanceNames = new HashMap<>(); + + for (Pnfs pnf : validate.getResources().getPnfs()) { + if (pnf.getModelInfo() == null) { + throw new ValidationException("modelInfo in userParams pnf resources", true); + } else if (pnf.getModelInfo().getModelCustomizationId() == null) { + throw new ValidationException("modelCustomizationId in userParams pnf resources", true); + } else if (pnf.getModelInfo().getModelVersionId() == null) { + throw new ValidationException("modelVersionId in userParams pnf resources", true); + } + String pnfCustomizationId = pnf.getModelInfo().getModelCustomizationId(); + pnfCustomIdToInstanceNames.putIfAbsent(pnfCustomizationId, new HashSet<>()); + String pnfInstanceName = StringUtils.defaultString(pnf.getInstanceName()); + Set pnfVisitedInstanceNames = pnfCustomIdToInstanceNames.get(pnfCustomizationId); + if (!pnfVisitedInstanceNames.add(pnfInstanceName)) { + throw new ValidationException( + "instanceName: same instanceName with same modelCustomizationId in userParams pnf resources", + true); + } + } + + validateDuplicateInstanceNames(pnfCustomIdToInstanceNames, "pnf"); + List validateNetworks = new ArrayList<>(); validateNetworks = validate.getResources().getNetworks(); if (validateNetworks != null) { -- cgit 1.2.3-korg