diff options
author | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2021-08-04 06:51:34 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-08-04 06:51:34 +0000 |
commit | 872613eafe80034cca612bd93294286b3dbed4b1 (patch) | |
tree | 0f14309d02bb1ea862368095a65ebfd04871884d /mso-api-handlers/mso-api-handler-infra/src/main/java/org | |
parent | e32fa2efac9f9b9e5a01a86f494664714042c352 (diff) | |
parent | ed5c51313c1bd3745a554888c969e840341599b0 (diff) |
Merge "Support instantiation of same model vnfs/vf-modules"
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java/org')
-rw-r--r-- | mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/UserParamsValidation.java | 63 |
1 files changed, 57 insertions, 6 deletions
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 067e8611d0..8646a74a2f 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 @@ -22,7 +22,13 @@ package org.onap.so.apihandlerinfra.validation; import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import org.apache.commons.lang3.StringUtils; import org.onap.so.apihandlerinfra.Action; import org.onap.so.apihandlerinfra.Actions; import org.onap.so.exceptions.ValidationException; @@ -36,8 +42,6 @@ public class UserParamsValidation implements ValidationRule { @Override public ValidationInformation validate(ValidationInformation info) throws ValidationException { Service validate = info.getUserParams(); - Actions action = info.getAction(); - if (validate.getModelInfo() == null) { throw new ValidationException("modelInfo in userParams", true); } else if (validate.getModelInfo().getModelType() == null) { @@ -49,6 +53,10 @@ public class UserParamsValidation implements ValidationRule { if (validate.getInstanceName() != null && info.getRequestInfo().getInstanceName() != null) { instanceNameValidation(info, validate); } + + Actions action = info.getAction(); + Map<String, Set<String>> vnfCustomIdToInstanceNames = new HashMap<>(); + Map<String, Set<String>> vfModuleCustomIdToInstanceNames = new HashMap<>(); for (Vnfs vnf : validate.getResources().getVnfs()) { if (vnf.getModelInfo() == null) { throw new ValidationException("modelInfo in userParams vnf resources", true); @@ -71,19 +79,42 @@ public class UserParamsValidation implements ValidationRule { if (vnf.getPlatform() != null && vnf.getPlatform().getPlatformName() == null) { throw new ValidationException("platformName in userParams vnf resources", true); } + + String vnfCustomizationId = vnf.getModelInfo().getModelCustomizationId(); + vnfCustomIdToInstanceNames.putIfAbsent(vnfCustomizationId, new HashSet<>()); + String vnfInstanceName = StringUtils.defaultString(vnf.getInstanceName()); + Set<String> vnfVisitedInstanceNames = vnfCustomIdToInstanceNames.get(vnfCustomizationId); + if (!vnfVisitedInstanceNames.add(vnfInstanceName)) { + throw new ValidationException( + "instanceName: same instanceName with same modelCustomizationId in userParams vnf resources", + true); + } if (vnf.getVfModules().isEmpty()) { throw new ValidationException("vfModules in userParams vnf resources", true); } - for (VfModules vfModules : vnf.getVfModules()) { - if (vfModules.getModelInfo() == null) { + + for (VfModules vfModule : vnf.getVfModules()) { + if (vfModule.getModelInfo() == null) { throw new ValidationException("modelInfo in userParams vfModules resources", true); - } else if (vfModules.getModelInfo().getModelCustomizationId() == null) { + } else if (vfModule.getModelInfo().getModelCustomizationId() == null) { throw new ValidationException("modelCustomizationId in userParams vfModule resources", true); - } else if (vfModules.getModelInfo().getModelVersionId() == null) { + } else if (vfModule.getModelInfo().getModelVersionId() == null) { throw new ValidationException("modelVersionId in userParams vfModule resources", true); } + + String vfModulecustomizationId = vfModule.getModelInfo().getModelCustomizationId(); + vfModuleCustomIdToInstanceNames.putIfAbsent(vfModulecustomizationId, new HashSet<>()); + String vfModuleInstanceName = StringUtils.defaultString(vfModule.getInstanceName()); + Set<String> vfModuleVisitedInstanceNames = vfModuleCustomIdToInstanceNames.get(vfModulecustomizationId); + if (!vfModuleVisitedInstanceNames.add(vfModuleInstanceName)) { + throw new ValidationException( + "instanceName: same instanceName with same modelCustomizationId in userParams vfModule resources", + true); + } } } + validateDuplicateInstanceNames(vnfCustomIdToInstanceNames, "vnf"); + validateDuplicateInstanceNames(vfModuleCustomIdToInstanceNames, "vfModule"); List<Networks> validateNetworks = new ArrayList<>(); validateNetworks = validate.getResources().getNetworks(); @@ -135,4 +166,24 @@ public class UserParamsValidation implements ValidationRule { "modelCustomizationId in userParams service"); } } + + private void validateDuplicateInstanceNames(Map<String, Set<String>> duplicateValidator, String type) + throws ValidationException { + Set<String> allInstanceNames = new HashSet<>(); + for (Map.Entry<String, Set<String>> entry : duplicateValidator.entrySet()) { + Set<String> instanceNames = entry.getValue(); + if (instanceNames.size() > 1 && instanceNames.contains("")) + throw new ValidationException(String.format( + "instanceName: instanceName is missing or empty with same modelCustomizationId in userParams %s resources", + type), true); + + for (String instanceName : instanceNames) { + if (!instanceName.isBlank() && !allInstanceNames.add(instanceName)) { + throw new ValidationException(String.format( + "instanceName: same instanceName but different modelCustomizationId (instanceName should be unique) in userParams %s resources", + type), true); + } + } + } + } } |