diff options
author | 2021-05-31 18:28:08 -0400 | |
---|---|---|
committer | 2021-07-30 12:24:31 -0400 | |
commit | ed5c51313c1bd3745a554888c969e840341599b0 (patch) | |
tree | 27b6ed17d52f0d8b14428c98b0886d60a70670bc /bpmn/MSOCommonBPMN/src/main | |
parent | 1be8408f26d3f20cf2ffb923a956b7ba6dfbd994 (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 'bpmn/MSOCommonBPMN/src/main')
8 files changed, 119 insertions, 24 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ResourceKey.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ResourceKey.java index 30a6e1fe35..641cd35027 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ResourceKey.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/ResourceKey.java @@ -34,5 +34,7 @@ public enum ResourceKey { VPN_ID, VPN_BONDING_LINK_ID, INSTANCE_GROUP_ID, - PNF + PNF, + VNF_INSTANCE_NAME, + VF_MODULE_INSTANCE_NAME } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/WorkflowResourceIds.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/WorkflowResourceIds.java index 508709e12c..5df7c60f74 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/WorkflowResourceIds.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/entities/WorkflowResourceIds.java @@ -40,6 +40,8 @@ public class WorkflowResourceIds implements Serializable { private String networkCollectionId; private String configurationId; private String instanceGroupId; + private String vnfInstanceName; + private String vfModuleInstanceName; public WorkflowResourceIds() { @@ -139,4 +141,20 @@ public class WorkflowResourceIds implements Serializable { public void setInstanceGroupId(String instanceGroupId) { this.instanceGroupId = instanceGroupId; } + + public String getVnfInstanceName() { + return vnfInstanceName; + } + + public void setVnfInstanceName(String vnfInstanceName) { + this.vnfInstanceName = vnfInstanceName; + } + + public String getVfModuleInstanceName() { + return vfModuleInstanceName; + } + + public void setVfModuleInstanceName(String vfModuleInstanceName) { + this.vfModuleInstanceName = vfModuleInstanceName; + } } diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index 83d1f5249f..569f6b1c77 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.UUID; +import org.apache.commons.lang3.StringUtils; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; import org.javatuples.Pair; @@ -74,6 +75,7 @@ import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds; import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.NoServiceInstanceFoundException; +import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.ResourceNotFoundException; import org.onap.so.bpmn.servicedecomposition.tasks.exceptions.ServiceModelNotFoundException; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization; @@ -258,6 +260,8 @@ public class BBInputSetup implements JavaDelegate { lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, workflowResourceIds.getVolumeGroupId()); lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, workflowResourceIds.getConfigurationId()); lookupKeyMap.put(ResourceKey.INSTANCE_GROUP_ID, workflowResourceIds.getInstanceGroupId()); + lookupKeyMap.put(ResourceKey.VNF_INSTANCE_NAME, workflowResourceIds.getVnfInstanceName()); + lookupKeyMap.put(ResourceKey.VF_MODULE_INSTANCE_NAME, workflowResourceIds.getVfModuleInstanceName()); } protected GeneralBuildingBlock getGBBALaCarteNonService(ExecuteBuildingBlock executeBB, @@ -1581,7 +1585,13 @@ public class BBInputSetup implements JavaDelegate { .setBbName(bbName).setServiceInstance(serviceInstance).setLookupKeyMap(lookupKeyMap).build(); if (bbName.contains(VNF) || (bbName.contains(CONTROLLER) && (VNF).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) { - vnfs = findVnfsByKey(key, resources, vnfs); + String vnfInstanceName = lookupKeyMap.get(ResourceKey.VNF_INSTANCE_NAME); + if (StringUtils.isNotBlank(vnfInstanceName)) { + vnfs = findVnfsByInstanceName(vnfInstanceName, resources); + } else { + vnfs = findVnfsByKey(key, resources); + } + String vnfId = lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID); // This stores the vnf id in request db to be retrieved later when // working on a vf module or volume group @@ -1611,15 +1621,15 @@ public class BBInputSetup implements JavaDelegate { .ifPresent(pnfs -> BBInputSetupPnf.populatePnfToServiceInstance(pnfs, pnfId, serviceInstance)); } else if (bbName.contains(VF_MODULE) || bbName.contains(VOLUME_GROUP) || (bbName.contains(CONTROLLER) && (VF_MODULE).equalsIgnoreCase(executeBB.getBuildingBlock().getBpmnScope()))) { - Pair<Vnfs, VfModules> vnfsAndVfModules = getVfModulesAndItsVnfsByKey(key, resources); - if (vnfsAndVfModules != null) { - vfModules = vnfsAndVfModules.getValue1(); - vnfs = vnfsAndVfModules.getValue0(); + String vfModuleInstanceName = lookupKeyMap.get(ResourceKey.VF_MODULE_INSTANCE_NAME); + if (StringUtils.isNotBlank(vfModuleInstanceName)) { + vfModules = getVfModulesByInstanceName(vfModuleInstanceName, resources); + } else { + vfModules = getVfModulesByKey(key, resources); } + lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, getVnfId(executeBB, lookupKeyMap)); - if (vnfs == null) { - throw new Exception("Could not find Vnf to orchestrate VfModule"); - } + parameter.setModelInfo(vfModules.getModelInfo()); if (bbName.contains(VOLUME_GROUP)) { parameter.setResourceId(lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID)); @@ -1682,25 +1692,45 @@ public class BBInputSetup implements JavaDelegate { return null; } - protected Pair<Vnfs, VfModules> getVfModulesAndItsVnfsByKey(String key, Resources resources) { + protected VfModules getVfModulesByInstanceName(String vfModuleInstanceName, Resources resources) { + for (Vnfs vnfs : resources.getVnfs()) { + for (VfModules vfModules : vnfs.getVfModules()) { + if (vfModules.getInstanceName().equals(vfModuleInstanceName)) { + return vfModules; + } + } + } + throw new ResourceNotFoundException( + "Could not find vf-module with instanceName: " + vfModuleInstanceName + " in userparams"); + } + + protected VfModules getVfModulesByKey(String key, Resources resources) { for (Vnfs vnfs : resources.getVnfs()) { for (VfModules vfModules : vnfs.getVfModules()) { if (vfModules.getModelInfo().getModelCustomizationId().equalsIgnoreCase(key)) { - return new Pair<Vnfs, VfModules>(vnfs, vfModules); + return vfModules; } } } - return null; + throw new ResourceNotFoundException("Could not find vf-module with key: " + key + " in userparams"); + } + + protected Vnfs findVnfsByInstanceName(String instanceName, Resources resources) { + for (Vnfs tempVnfs : resources.getVnfs()) { + if (tempVnfs.getInstanceName().equals(instanceName)) { + return tempVnfs; + } + } + throw new ResourceNotFoundException("Could not find vnf with instanceName: " + instanceName + " in userparams"); } - protected Vnfs findVnfsByKey(String key, Resources resources, Vnfs vnfs) { + protected Vnfs findVnfsByKey(String key, Resources resources) { for (Vnfs tempVnfs : resources.getVnfs()) { if (tempVnfs.getModelInfo().getModelCustomizationId().equalsIgnoreCase(key)) { - vnfs = tempVnfs; - break; + return tempVnfs; } } - return vnfs; + throw new ResourceNotFoundException("Could not find vnf with key: " + key + " in userparams"); } protected CloudRegion getCloudRegionFromMacroRequest(CloudConfiguration cloudConfiguration, Resources resources) { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/ResourceNotFoundException.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/ResourceNotFoundException.java new file mode 100644 index 0000000000..d8eed9610a --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/exceptions/ResourceNotFoundException.java @@ -0,0 +1,14 @@ +package org.onap.so.bpmn.servicedecomposition.tasks.exceptions; + +public class ResourceNotFoundException extends RuntimeException { + + static final long serialVersionUID = -2741357347054072719L; + + public ResourceNotFoundException() { + super(); + } + + public ResourceNotFoundException(String message) { + super(message); + } +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java index 6f850fa898..eeaecb9264 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVfModule.java @@ -21,7 +21,7 @@ package org.onap.so.client.cds; import com.google.gson.JsonObject; -import org.onap.so.client.cds.ExtractServiceFromUserParameters; +import org.apache.commons.lang3.StringUtils; import org.onap.so.client.exception.PayloadGenerationException; import org.onap.so.serviceinstancebeans.Service; import org.onap.so.serviceinstancebeans.VfModules; @@ -47,12 +47,17 @@ public class ConfigureInstanceParamsForVfModule { * @throws PayloadGenerationException- If it doesn't able to populate instance parameters from SO payload. */ public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest, - String vnfCustomizationUuid, String vfModuleCustomizationUuid) throws PayloadGenerationException { + String vnfCustomizationUuid, String vfModuleCustomizationUuid, String vfModuleInstanceName) + throws PayloadGenerationException { try { Service service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest); - List<Map<String, String>> instanceParamsList = - getInstanceParams(service, vnfCustomizationUuid, vfModuleCustomizationUuid); + List<Map<String, String>> instanceParamsList; + if (StringUtils.isNotBlank(vfModuleInstanceName)) { + instanceParamsList = getInstanceParamsByInstanceNames(service, vfModuleInstanceName); + } else { + instanceParamsList = getInstanceParams(service, vnfCustomizationUuid, vfModuleCustomizationUuid); + } instanceParamsList.stream().flatMap(instanceParamsMap -> instanceParamsMap.entrySet().stream()) .forEachOrdered(entry -> jsonObject.addProperty(entry.getKey(), entry.getValue())); @@ -61,6 +66,14 @@ public class ConfigureInstanceParamsForVfModule { } } + private List<Map<String, String>> getInstanceParamsByInstanceNames(Service service, String vfModuleInstanceName) + throws PayloadGenerationException { + return service.getResources().getVnfs().stream().map(Vnfs::getVfModules).flatMap(List::stream) + .filter(vfm -> vfModuleInstanceName.equals(vfm.getInstanceName())).findFirst() + .map(VfModules::getInstanceParams).orElseThrow(() -> new PayloadGenerationException( + "Could not find vfModule with instanceName: " + vfModuleInstanceName)); + } + private List<Map<String, String>> getInstanceParams(Service service, String vnfCustomizationUuid, String vfModuleCustomizationUuid) throws PayloadGenerationException { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java index 22c9a7bee4..43283ac98b 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/ConfigureInstanceParamsForVnf.java @@ -21,6 +21,7 @@ package org.onap.so.client.cds; import com.google.gson.JsonObject; +import org.apache.commons.lang3.StringUtils; import org.onap.so.client.exception.PayloadGenerationException; import org.onap.so.serviceinstancebeans.Service; import org.onap.so.serviceinstancebeans.Vnfs; @@ -45,10 +46,16 @@ public class ConfigureInstanceParamsForVnf { * @throws PayloadGenerationException if it doesn't able to populate instance parameters from SO payload. */ public void populateInstanceParams(JsonObject jsonObject, List<Map<String, Object>> userParamsFromRequest, - String modelCustomizationUuid) throws PayloadGenerationException { + String modelCustomizationUuid, String vnfInstanceName) throws PayloadGenerationException { try { Service service = extractServiceFromUserParameters.getServiceFromRequestUserParams(userParamsFromRequest); - List<Map<String, String>> instanceParamsList = getInstanceParamForVnf(service, modelCustomizationUuid); + + List<Map<String, String>> instanceParamsList; + if (StringUtils.isNotBlank(vnfInstanceName)) { + instanceParamsList = getInstanceParamByVnfInstanceName(service, vnfInstanceName); + } else { + instanceParamsList = getInstanceParamForVnf(service, modelCustomizationUuid); + } instanceParamsList.stream().flatMap(instanceParamsMap -> instanceParamsMap.entrySet().stream()) .forEachOrdered(entry -> jsonObject.addProperty(entry.getKey(), entry.getValue())); @@ -57,6 +64,13 @@ public class ConfigureInstanceParamsForVnf { } } + private List<Map<String, String>> getInstanceParamByVnfInstanceName(Service service, String instanceName) + throws PayloadGenerationException { + return service.getResources().getVnfs().stream().filter(vnf -> instanceName.equals(vnf.getInstanceName())) + .findFirst().map(Vnfs::getInstanceParams).orElseThrow( + () -> new PayloadGenerationException("Could not find vnf with instanceName: " + instanceName)); + } + private List<Map<String, String>> getInstanceParamForVnf(Service service, String genericVnfModelCustomizationUuid) throws PayloadGenerationException { Optional<Vnfs> foundedVnf = service.getResources().getVnfs().stream() diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java index 478b65c349..06ab84a114 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VfModuleCDSRequestProvider.java @@ -104,9 +104,11 @@ public class VfModuleCDSRequestProvider implements CDSRequestProvider { final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock(); List<Map<String, Object>> userParamsFromRequest = buildingBlock.getRequestContext().getRequestParameters().getUserParams(); + String vfModuleInstanceName = + execution.getLookupMap().getOrDefault(ResourceKey.VF_MODULE_INSTANCE_NAME, ""); if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) { configureInstanceParamsForVfModule.populateInstanceParams(vfModuleObject, userParamsFromRequest, - modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule); + modelCustomizationUuidForVnf, modelCustomizationUuidForVfModule, vfModuleInstanceName); } } catch (Exception e) { throw new PayloadGenerationException("Failed to buildPropertyObject for VF-Module", e); diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java index 6251eb6fad..5f63732458 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/cds/VnfCDSRequestProvider.java @@ -23,6 +23,7 @@ package org.onap.so.client.cds; import com.google.gson.JsonObject; +import org.apache.commons.lang3.StringUtils; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; @@ -93,9 +94,10 @@ public class VnfCDSRequestProvider implements CDSRequestProvider { final GeneralBuildingBlock buildingBlock = execution.getGeneralBuildingBlock(); List<Map<String, Object>> userParamsFromRequest = buildingBlock.getRequestContext().getRequestParameters().getUserParams(); + String vnfInstanceName = execution.getLookupMap().getOrDefault(ResourceKey.VNF_INSTANCE_NAME, ""); if (userParamsFromRequest != null && userParamsFromRequest.size() != 0) { configureInstanceParamsForVnf.populateInstanceParams(vnfObject, userParamsFromRequest, - modelCustomizationUuid); + modelCustomizationUuid, vnfInstanceName); } } catch (Exception e) { throw new PayloadGenerationException("Failed to buildPropertyObjectForVnf", e); |