summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main
diff options
context:
space:
mode:
authorMichael Pruss <michael.pruss@bell.ca>2021-05-31 18:28:08 -0400
committerJozsef Csongvai <jozsef.csongvai@bell.ca>2021-07-30 12:24:31 -0400
commited5c51313c1bd3745a554888c969e840341599b0 (patch)
tree27b6ed17d52f0d8b14428c98b0886d60a70670bc /mso-api-handlers/mso-api-handler-infra/src/main
parent1be8408f26d3f20cf2ffb923a956b7ba6dfbd994 (diff)
Support instantiation of same model vnfs/vf-modules
When instantiating a service with multiple vnfs and/or vfmodules SO would differentiate using ModelCustomizationId. This would cause issues when creating multiple instances of same model resource, and each lookup would return the same object. Instead of using ModelCustomizationId, this patch enables SO to use instanceName parameter to differentiate the resources. Validation was added to ensure that instanceNames are provided if there are multiple resources of the same model. If there are no duplicate resources and instanceName is not set, SO will default to previous logic using ModelCustomizationId. In order to properly associate vfmodules with their parent vnfs, the Resource class was augmented with a parent reference which maintains the relationship in further processing. Id generation logic was corrected to ensure that multiple resources of the same model are assigned unique instance ids and references to parent instanceId. Issue-ID: SO-3677 Change-Id: If39a0138f501177e12262f8e911137012e287fca Signed-off-by: Michael Pruss <michael.pruss@bell.ca>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/UserParamsValidation.java63
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);
+ }
+ }
+ }
+ }
}