Merge "add junit coverage"
[so.git] / bpmn / MSOCommonBPMN / src / main / java / org / onap / so / bpmn / servicedecomposition / tasks / BBInputSetup.java
index 3cf5a60..88c36be 100644 (file)
@@ -62,6 +62,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.ServiceModelNotFoundException;
 import org.onap.so.client.aai.AAICommonObjectMapperProvider;
 import org.onap.so.client.aai.AAIObjectType;
 import org.onap.so.client.aai.entities.AAIResultWrapper;
@@ -83,6 +84,7 @@ import org.onap.so.db.catalog.beans.VfModuleCustomization;
 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
 import org.onap.so.db.request.beans.InfraActiveRequests;
+import org.onap.so.db.request.client.RequestsDbClient;
 import org.onap.so.serviceinstancebeans.CloudConfiguration;
 import org.onap.so.serviceinstancebeans.ModelInfo;
 import org.onap.so.serviceinstancebeans.ModelType;
@@ -115,6 +117,7 @@ public class BBInputSetup implements JavaDelegate {
     private static final String VNF = "Vnf";
     private static final String NETWORK_COLLECTION = "NetworkCollection";
     private static final String PREPROV = "PREPROV";
+    private static final String CREATEVOLUME = "CreateVolume";
 
     @Autowired
     private BBInputSetupUtils bbInputSetupUtils;
@@ -128,6 +131,9 @@ public class BBInputSetup implements JavaDelegate {
     @Autowired
     private ExceptionBuilder exceptionUtil;
 
+    @Autowired
+    private RequestsDbClient requestsDbClient;
+
     private ObjectMapper mapper = new ObjectMapper();
 
     public BBInputSetupUtils getBbInputSetupUtils() {
@@ -249,26 +255,46 @@ public class BBInputSetup implements JavaDelegate {
         String bbName = executeBB.getBuildingBlock().getBpmnFlowName();
         String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
         org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance = null;
+        Service service = null;
+        boolean isReplace = false;
         if (serviceInstanceId != null) {
             aaiServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
+            if (aaiServiceInstance != null) {
+                if (requestAction.equalsIgnoreCase("replaceInstance")) {
+                    RelatedInstanceList[] relatedInstanceList = requestDetails.getRelatedInstanceList();
+                    if (relatedInstanceList != null) {
+                        for (RelatedInstanceList relatedInstList : relatedInstanceList) {
+                            RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
+                            if (relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) {
+                                service = bbInputSetupUtils.getCatalogServiceByModelUUID(
+                                        relatedInstance.getModelInfo().getModelVersionId());
+                                isReplace = true;
+                            }
+                        }
+                    }
+                } else {
+                    service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId());
+                }
+                if (service == null) {
+                    String message = String.format(
+                            "Related service instance model not found in MSO CatalogDB: model-version-id=%s",
+                            aaiServiceInstance.getModelVersionId());
+                    throw new ServiceModelNotFoundException(message);
+                }
+            } else {
+                String message = String.format("Related service instance from AAI not found: service-instance-id=%s",
+                        serviceInstanceId);
+                throw new NoServiceInstanceFoundException(message);
+            }
         }
-        Service service = null;
-        if (aaiServiceInstance != null) {
-            service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId());
-        }
-        if (aaiServiceInstance != null && service != null) {
-            ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance);
-            serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service));
-            this.populateObjectsOnAssignAndCreateFlows(requestDetails, service, bbName, serviceInstance, lookupKeyMap,
-                    resourceId, vnfType, executeBB.getBuildingBlock().getKey(),
-                    executeBB.getConfigurationResourceKeys());
-            return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction,
-                    null);
-        } else {
-            logger.debug("Related Service Instance from AAI: {}", aaiServiceInstance);
-            logger.debug("Related Service Instance Model Info from AAI: {}", service);
-            throw new Exception("Could not find relevant information for related Service Instance");
-        }
+
+        ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance);
+        serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service));
+        this.populateObjectsOnAssignAndCreateFlows(executeBB.getRequestId(), requestDetails, service, bbName,
+                serviceInstance, lookupKeyMap, resourceId, vnfType, executeBB.getBuildingBlock().getKey(),
+                executeBB.getConfigurationResourceKeys(), isReplace);
+        return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, null);
+
     }
 
     protected GeneralBuildingBlock getGBBCM(ExecuteBuildingBlock executeBB, RequestDetails requestDetails,
@@ -284,6 +310,9 @@ public class BBInputSetup implements JavaDelegate {
             org.onap.aai.domain.yang.GenericVnf aaiGenericVnf = bbInputSetupUtils.getAAIGenericVnf(vnfId);
             GenericVnf genericVnf = this.mapperLayer.mapAAIGenericVnfIntoGenericVnf(aaiGenericVnf);
             genericVnfs.add(genericVnf);
+            if (genericVnf != null) {
+                updateInstanceName(executeBB.getRequestId(), ModelType.vnf, genericVnf.getVnfName());
+            }
         }
 
         String instanceGroupId = lookupKeyMap.get(ResourceKey.INSTANCE_GROUP_ID);
@@ -292,6 +321,7 @@ public class BBInputSetup implements JavaDelegate {
                     bbInputSetupUtils.getAAIInstanceGroup(instanceGroupId);
             InstanceGroup instanceGroup = this.mapperLayer.mapAAIInstanceGroupIntoInstanceGroup(aaiInstancegroup);
             instanceGroup.setOrchestrationStatus(OrchestrationStatus.INVENTORIED);
+            updateInstanceName(executeBB.getRequestId(), ModelType.instanceGroup, instanceGroup.getInstanceGroupName());
 
             if (serviceInstanceId == null) {
                 Optional<org.onap.aai.domain.yang.ServiceInstance> aaiServiceInstanceOpt =
@@ -326,9 +356,10 @@ public class BBInputSetup implements JavaDelegate {
                 customer);
     }
 
-    protected void populateObjectsOnAssignAndCreateFlows(RequestDetails requestDetails, Service service, String bbName,
-            ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId, String vnfType,
-            String configurationKey, ConfigurationResourceKeys configurationResourceKeys) throws Exception {
+    protected void populateObjectsOnAssignAndCreateFlows(String requestId, RequestDetails requestDetails,
+            Service service, String bbName, ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap,
+            String resourceId, String vnfType, String configurationKey,
+            ConfigurationResourceKeys configurationResourceKeys, boolean isReplace) throws Exception {
         ModelInfo modelInfo = requestDetails.getModelInfo();
         String instanceName = requestDetails.getRequestInfo().getInstanceName();
         String productFamilyId = requestDetails.getRequestInfo().getProductFamilyId();
@@ -337,30 +368,36 @@ public class BBInputSetup implements JavaDelegate {
 
         org.onap.so.serviceinstancebeans.Platform platform = requestDetails.getPlatform();
         org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness = requestDetails.getLineOfBusiness();
+        String applicationId = "";
+        if (requestDetails.getRequestInfo().getApplicationId() != null) {
+            applicationId = requestDetails.getRequestInfo().getApplicationId();
+        }
 
         if (modelType.equals(ModelType.network)) {
             lookupKeyMap.put(ResourceKey.NETWORK_ID, resourceId);
-            this.populateL3Network(instanceName, modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId,
-                    null);
+            this.populateL3Network(requestId, instanceName, modelInfo, service, bbName, serviceInstance, lookupKeyMap,
+                    resourceId, null);
         } else if (modelType.equals(ModelType.vnf)) {
             lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, resourceId);
-            this.populateGenericVnf(modelInfo, instanceName, platform, lineOfBusiness, service, bbName, serviceInstance,
-                    lookupKeyMap, relatedInstanceList, resourceId, vnfType, null, productFamilyId);
-        } else if (modelType.equals(ModelType.volumeGroup)) {
+            this.populateGenericVnf(requestId, modelInfo, instanceName, platform, lineOfBusiness, service, bbName,
+                    serviceInstance, lookupKeyMap, relatedInstanceList, resourceId, vnfType, null, productFamilyId,
+                    applicationId);
+        } else if (modelType.equals(ModelType.volumeGroup) || (modelType.equals(ModelType.vfModule)
+                && (bbName.equalsIgnoreCase(AssignFlows.VOLUME_GROUP.toString()) || bbName.startsWith(CREATEVOLUME)))) {
             lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, resourceId);
-            this.populateVolumeGroup(modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId,
+            this.populateVolumeGroup(requestId, modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId,
                     relatedInstanceList, instanceName, vnfType, null);
         } else if (modelType.equals(ModelType.vfModule)) {
             if (bbName.contains("Configuration")) {
                 String configurationId = lookupKeyMap.get(ResourceKey.CONFIGURATION_ID);
                 ModelInfo configurationModelInfo = new ModelInfo();
                 configurationModelInfo.setModelCustomizationUuid(configurationKey);
-                populateConfiguration(configurationModelInfo, service, bbName, serviceInstance, lookupKeyMap,
+                populateConfiguration(requestId, configurationModelInfo, service, bbName, serviceInstance, lookupKeyMap,
                         configurationId, instanceName, configurationResourceKeys, requestDetails);
             } else {
                 lookupKeyMap.put(ResourceKey.VF_MODULE_ID, resourceId);
-                this.populateVfModule(modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId,
-                        relatedInstanceList, instanceName, null, requestDetails.getCloudConfiguration());
+                this.populateVfModule(requestId, modelInfo, service, bbName, serviceInstance, lookupKeyMap, resourceId,
+                        relatedInstanceList, instanceName, null, requestDetails.getCloudConfiguration(), isReplace);
             }
         } else if (modelType.equals(ModelType.instanceGroup)) {
             lookupKeyMap.put(ResourceKey.INSTANCE_GROUP_ID, resourceId);
@@ -384,16 +421,13 @@ public class BBInputSetup implements JavaDelegate {
         // Dependent on MSO-5821 653458 US - MSO - Enhance Catalog DB Schema & Adapter to support VNF Groups
     }
 
-    protected void populateConfiguration(ModelInfo modelInfo, Service service, String bbName,
+    protected void populateConfiguration(String requestId, ModelInfo modelInfo, Service service, String bbName,
             ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId,
             String instanceName, ConfigurationResourceKeys configurationResourceKeys, RequestDetails requestDetails) {
         Configuration configuration = null;
         for (Configuration configurationTemp : serviceInstance.getConfigurations()) {
-            if ((bbName.contains("Fabric") && configurationTemp.getConfigurationSubType() != null
-                    && configurationTemp.getConfigurationSubType().equalsIgnoreCase("Fabric Config"))
-                    || (lookupKeyMap.get(ResourceKey.CONFIGURATION_ID) != null && configurationTemp.getConfigurationId()
-                            .equalsIgnoreCase(lookupKeyMap.get(ResourceKey.CONFIGURATION_ID)))) {
-                lookupKeyMap.put(ResourceKey.CONFIGURATION_ID, configurationTemp.getConfigurationId());
+            if (lookupKeyMap.get(ResourceKey.CONFIGURATION_ID) != null && configurationTemp.getConfigurationId()
+                    .equalsIgnoreCase(lookupKeyMap.get(ResourceKey.CONFIGURATION_ID))) {
                 configuration = configurationTemp;
                 org.onap.aai.domain.yang.Configuration aaiConfiguration =
                         bbInputSetupUtils.getAAIConfiguration(configuration.getConfigurationId());
@@ -411,11 +445,13 @@ public class BBInputSetup implements JavaDelegate {
             Vnfc vnfc = getVnfcToConfiguration(configurationResourceKeys.getVnfcName());
             configuration.setVnfc(vnfc);
             this.mapCatalogConfiguration(configuration, modelInfo, service, configurationResourceKeys);
+            updateInstanceName(requestId, ModelType.configuration, configuration.getConfigurationName());
         } else if (configuration != null && bbName.contains("Vrf")) {
             configuration.setModelInfoConfiguration(mapperLayer.mapCatalogConfigurationToConfiguration(
                     findConfigurationResourceCustomization(modelInfo, service), null));
             configuration.setConfigurationType(configuration.getModelInfoConfiguration().getConfigurationType());
             configuration.setConfigurationSubType(configuration.getModelInfoConfiguration().getConfigurationRole());
+            updateInstanceName(requestId, ModelType.configuration, configuration.getConfigurationName());
         }
     }
 
@@ -490,16 +526,21 @@ public class BBInputSetup implements JavaDelegate {
                 vfModuleCustomizationUUID, cvnfcCustomizationUUID);
     }
 
-    protected void populateVfModule(ModelInfo modelInfo, Service service, String bbName,
+    protected void populateVfModule(String requestId, ModelInfo modelInfo, Service service, String bbName,
             ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId,
             RelatedInstanceList[] relatedInstanceList, String instanceName, List<Map<String, String>> instanceParams,
-            CloudConfiguration cloudConfiguration) throws Exception {
+            CloudConfiguration cloudConfiguration, boolean isReplace) throws Exception {
+        String replaceVnfModelCustomizationUUID = null;
         String vnfModelCustomizationUUID = null;
         if (relatedInstanceList != null) {
             for (RelatedInstanceList relatedInstList : relatedInstanceList) {
                 RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
                 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
-                    vnfModelCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
+                    if (isReplace) {
+                        replaceVnfModelCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
+                    } else {
+                        vnfModelCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
+                    }
                 }
                 if (relatedInstance.getModelInfo().getModelType().equals(ModelType.volumeGroup)) {
                     lookupKeyMap.put(ResourceKey.VOLUME_GROUP_ID, relatedInstance.getInstanceId());
@@ -534,12 +575,23 @@ public class BBInputSetup implements JavaDelegate {
                         .getModelCustomizationId();
                 ModelInfo modelInfoVfModule = new ModelInfo();
                 modelInfoVfModule.setModelCustomizationId(vfModuleCustId);
-                mapCatalogVfModule(vfModuleTemp, modelInfoVfModule, service, vnfModelCustomizationUUID);
+                if (isReplace) {
+                    mapCatalogVfModule(vfModuleTemp, modelInfoVfModule, service, replaceVnfModelCustomizationUUID);
+                } else {
+                    mapCatalogVfModule(vfModuleTemp, modelInfoVfModule, service, vnfModelCustomizationUUID);
+                }
             }
             if (vfModule == null && bbName.equalsIgnoreCase(AssignFlows.VF_MODULE.toString())) {
                 vfModule = createVfModule(lookupKeyMap, resourceId, instanceName, instanceParams);
                 vnf.getVfModules().add(vfModule);
-                mapCatalogVfModule(vfModule, modelInfo, service, vnfModelCustomizationUUID);
+                if (isReplace) {
+                    mapCatalogVfModule(vfModule, modelInfo, service, replaceVnfModelCustomizationUUID);
+                } else {
+                    mapCatalogVfModule(vfModule, modelInfo, service, vnfModelCustomizationUUID);
+                }
+            }
+            if (vfModule != null) {
+                updateInstanceName(requestId, ModelType.vfModule, vfModule.getVfModuleName());
             }
         } else {
             logger.debug("Related VNF instance Id not found: {}", lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID));
@@ -555,6 +607,7 @@ public class BBInputSetup implements JavaDelegate {
                         bbInputSetupUtils.getAAIVolumeGroup(cloudOwner, cloudRegionId, volumeGroup.getVolumeGroupId())
                                 .getModelCustomizationId();
                 if (modelInfo.getModelCustomizationId().equalsIgnoreCase(volumeGroupCustId)) {
+                    logger.debug("Found volume group for vfModule: " + volumeGroup.getVolumeGroupId());
                     return Optional.of(volumeGroup.getVolumeGroupId());
                 }
             }
@@ -604,7 +657,7 @@ public class BBInputSetup implements JavaDelegate {
         return vfModule;
     }
 
-    protected void populateVolumeGroup(ModelInfo modelInfo, Service service, String bbName,
+    protected void populateVolumeGroup(String requestId, ModelInfo modelInfo, Service service, String bbName,
             ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId,
             RelatedInstanceList[] relatedInstanceList, String instanceName, String vnfType,
             List<Map<String, String>> instanceParams) throws Exception {
@@ -650,6 +703,7 @@ public class BBInputSetup implements JavaDelegate {
             }
             if (volumeGroup != null) {
                 mapCatalogVolumeGroup(volumeGroup, modelInfo, service, vnfModelCustomizationUUID);
+                updateInstanceName(requestId, ModelType.volumeGroup, volumeGroup.getVolumeGroupName());
             }
         } else {
             logger.debug("Related VNF instance Id not found: {}", lookupKeyMap.get(ResourceKey.GENERIC_VNF_ID));
@@ -703,12 +757,12 @@ public class BBInputSetup implements JavaDelegate {
         return null;
     }
 
-    protected void populateGenericVnf(ModelInfo modelInfo, String instanceName,
+    protected void populateGenericVnf(String requestId, ModelInfo modelInfo, String instanceName,
             org.onap.so.serviceinstancebeans.Platform platform,
             org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness, Service service, String bbName,
             ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap,
             RelatedInstanceList[] relatedInstanceList, String resourceId, String vnfType,
-            List<Map<String, String>> instanceParams, String productFamilyId) {
+            List<Map<String, String>> instanceParams, String productFamilyId, String applicationId) {
         GenericVnf vnf = null;
         ModelInfo instanceGroupModelInfo = null;
         String instanceGroupId = null;
@@ -737,7 +791,7 @@ public class BBInputSetup implements JavaDelegate {
         }
         if (vnf == null && bbName.equalsIgnoreCase(AssignFlows.VNF.toString())) {
             vnf = createGenericVnf(lookupKeyMap, instanceName, platform, lineOfBusiness, resourceId, generatedVnfType,
-                    instanceParams, productFamilyId);
+                    instanceParams, productFamilyId, applicationId);
             serviceInstance.getVnfs().add(vnf);
             mapVnfcCollectionInstanceGroup(vnf, modelInfo, service);
         }
@@ -748,6 +802,7 @@ public class BBInputSetup implements JavaDelegate {
                     && !instanceGroupInList(vnf, instanceGroupId)) {
                 mapNetworkCollectionInstanceGroup(vnf, instanceGroupId);
             }
+            updateInstanceName(requestId, ModelType.vnf, vnf.getVnfName());
         }
     }
 
@@ -790,7 +845,7 @@ public class BBInputSetup implements JavaDelegate {
     protected GenericVnf createGenericVnf(Map<ResourceKey, String> lookupKeyMap, String instanceName,
             org.onap.so.serviceinstancebeans.Platform platform,
             org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness, String vnfId, String vnfType,
-            List<Map<String, String>> instanceParams, String productFamilyId) {
+            List<Map<String, String>> instanceParams, String productFamilyId, String applicationId) {
         lookupKeyMap.put(ResourceKey.GENERIC_VNF_ID, vnfId);
         GenericVnf genericVnf = new GenericVnf();
         genericVnf.setVnfId(vnfId);
@@ -799,6 +854,7 @@ public class BBInputSetup implements JavaDelegate {
         genericVnf.setVnfType(vnfType);
         genericVnf.setProvStatus(PREPROV);
         genericVnf.setServiceId(productFamilyId);
+        genericVnf.setApplicationId(applicationId);
         if (platform != null) {
             genericVnf.setPlatform(this.mapperLayer.mapRequestPlatform(platform));
         }
@@ -831,8 +887,8 @@ public class BBInputSetup implements JavaDelegate {
         return vnfResourceCustomization;
     }
 
-    protected void populateL3Network(String instanceName, ModelInfo modelInfo, Service service, String bbName,
-            ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId,
+    protected void populateL3Network(String requestId, String instanceName, ModelInfo modelInfo, Service service,
+            String bbName, ServiceInstance serviceInstance, Map<ResourceKey, String> lookupKeyMap, String resourceId,
             List<Map<String, String>> instanceParams) {
         L3Network network = null;
         for (L3Network networkTemp : serviceInstance.getNetworks()) {
@@ -849,6 +905,7 @@ public class BBInputSetup implements JavaDelegate {
         }
         if (network != null) {
             mapCatalogNetwork(network, modelInfo, service);
+            updateInstanceName(requestId, ModelType.network, network.getNetworkName());
         }
     }
 
@@ -908,6 +965,7 @@ public class BBInputSetup implements JavaDelegate {
             ServiceInstance serviceInstance = this.getALaCarteServiceInstance(service, requestDetails, customer,
                     project, owningEntity, lookupKeyMap, resourceId, Boolean.TRUE.equals(executeBB.isaLaCarte()),
                     executeBB.getBuildingBlock().getBpmnFlowName());
+            updateInstanceName(executeBB.getRequestId(), ModelType.service, serviceInstance.getServiceInstanceName());
             return this.populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction,
                     customer);
         } else {
@@ -1116,8 +1174,8 @@ public class BBInputSetup implements JavaDelegate {
                 NetworkResourceCustomization networkCust = getNetworkCustomizationByKey(key, service);
                 if (networkCust != null) {
                     networkModelInfo.setModelCustomizationUuid(networkCust.getModelCustomizationUUID());
-                    this.populateL3Network(null, networkModelInfo, service, bbName, serviceInstance, lookupKeyMap,
-                            networkId, null);
+                    this.populateL3Network(executeBB.getRequestId(), null, networkModelInfo, service, bbName,
+                            serviceInstance, lookupKeyMap, networkId, null);
                 } else {
                     logger.debug("Could not find a network customization with key: {}", key);
                 }
@@ -1137,8 +1195,9 @@ public class BBInputSetup implements JavaDelegate {
             String configurationId = lookupKeyMap.get(ResourceKey.CONFIGURATION_ID);
             ModelInfo configurationModelInfo = new ModelInfo();
             configurationModelInfo.setModelCustomizationUuid(key);
-            this.populateConfiguration(configurationModelInfo, service, bbName, serviceInstance, lookupKeyMap,
-                    configurationId, null, executeBB.getConfigurationResourceKeys(), executeBB.getRequestDetails());
+            this.populateConfiguration(executeBB.getRequestId(), configurationModelInfo, service, bbName,
+                    serviceInstance, lookupKeyMap, configurationId, null, executeBB.getConfigurationResourceKeys(),
+                    executeBB.getRequestDetails());
         }
         if (executeBB.getWorkflowResourceIds() != null) {
             this.populateNetworkCollectionAndInstanceGroupAssign(service, bbName, serviceInstance,
@@ -1235,23 +1294,30 @@ public class BBInputSetup implements JavaDelegate {
         String serviceInstanceId = lookupKeyMap.get(ResourceKey.SERVICE_INSTANCE_ID);
         RequestDetails requestDetails = executeBB.getRequestDetails();
         GeneralBuildingBlock gBB = null;
+        Service service = null;
         if (serviceInstanceId != null) {
             aaiServiceInstance = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId);
+            if (aaiServiceInstance != null) {
+                service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId());
+                if (service == null) {
+                    String message = String.format(
+                            "Related service instance model not found in MSO CatalogDB: model-version-id=%s",
+                            aaiServiceInstance.getModelVersionId());
+                    throw new ServiceModelNotFoundException(message);
+                }
+            } else {
+                String message = String.format("Related service instance from AAI not found: service-instance-id=%s",
+                        serviceInstanceId);
+                throw new NoServiceInstanceFoundException(message);
+            }
         }
-        Service service = null;
-        if (aaiServiceInstance != null) {
-            service = bbInputSetupUtils.getCatalogServiceByModelUUID(aaiServiceInstance.getModelVersionId());
-        }
-        if (aaiServiceInstance != null && service != null) {
-            ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance);
-            serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service));
-            gBB = populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, null);
-        } else {
-            logger.debug("Related Service Instance from AAI: {}", aaiServiceInstance);
-            logger.debug("Related Service Instance Model Info from AAI: {}", service);
-            throw new Exception("Could not find relevant information for related Service Instance");
-        }
-        ServiceInstance serviceInstance = gBB.getServiceInstance();
+
+        ServiceInstance serviceInstance = this.getExistingServiceInstance(aaiServiceInstance);
+        serviceInstance.setModelInfoServiceInstance(this.mapperLayer.mapCatalogServiceIntoServiceInstance(service));
+        updateInstanceName(executeBB.getRequestId(), ModelType.service, serviceInstance.getServiceInstanceName());
+        gBB = populateGBBWithSIAndAdditionalInfo(requestDetails, serviceInstance, executeBB, requestAction, null);
+
+        serviceInstance = gBB.getServiceInstance();
         CloudRegion cloudRegion = null;
         if (cloudConfiguration == null) {
             Optional<CloudRegion> cloudRegionOp = cloudInfoFromAAI.getCloudInfoFromAAI(serviceInstance);
@@ -1386,9 +1452,10 @@ public class BBInputSetup implements JavaDelegate {
                 this.bbInputSetupUtils.updateInfraActiveRequestVnfId(request, vnfId);
             }
             String productFamilyId = requestDetails.getRequestInfo().getProductFamilyId();
-            this.populateGenericVnf(vnfs.getModelInfo(), vnfs.getInstanceName(), vnfs.getPlatform(),
-                    vnfs.getLineOfBusiness(), service, bbName, serviceInstance, lookupKeyMap, null, vnfId, vnfType,
-                    vnfs.getInstanceParams(), productFamilyId);
+            String applicationId = "";
+            this.populateGenericVnf(executeBB.getRequestId(), vnfs.getModelInfo(), vnfs.getInstanceName(),
+                    vnfs.getPlatform(), vnfs.getLineOfBusiness(), service, bbName, serviceInstance, lookupKeyMap, null,
+                    vnfId, vnfType, vnfs.getInstanceParams(), productFamilyId, applicationId);
         } else if (bbName.contains(VF_MODULE) || bbName.contains(VOLUME_GROUP)) {
             Pair<Vnfs, VfModules> vnfsAndVfModules = getVfModulesAndItsVnfsByKey(key, resources);
             if (vnfsAndVfModules != null) {
@@ -1402,22 +1469,24 @@ public class BBInputSetup implements JavaDelegate {
             ModelInfo modelInfo = vfModules.getModelInfo();
             if (bbName.contains(VOLUME_GROUP)) {
                 String volumeGroupId = lookupKeyMap.get(ResourceKey.VOLUME_GROUP_ID);
-                this.populateVolumeGroup(modelInfo, service, bbName, serviceInstance, lookupKeyMap, volumeGroupId, null,
-                        vfModules.getVolumeGroupInstanceName(), vnfType, vfModules.getInstanceParams());
+                this.populateVolumeGroup(executeBB.getRequestId(), modelInfo, service, bbName, serviceInstance,
+                        lookupKeyMap, volumeGroupId, null, vfModules.getVolumeGroupInstanceName(), vnfType,
+                        vfModules.getInstanceParams());
             } else {
                 String vfModuleId = lookupKeyMap.get(ResourceKey.VF_MODULE_ID);
                 CloudConfiguration cloudConfig = new CloudConfiguration();
                 cloudConfig.setLcpCloudRegionId(cloudRegion.getLcpCloudRegionId());
                 cloudConfig.setCloudOwner(cloudRegion.getCloudOwner());
-                this.populateVfModule(modelInfo, service, bbName, serviceInstance, lookupKeyMap, vfModuleId, null,
-                        vfModules.getInstanceName(), vfModules.getInstanceParams(), cloudConfig);
+                this.populateVfModule(executeBB.getRequestId(), modelInfo, service, bbName, serviceInstance,
+                        lookupKeyMap, vfModuleId, null, vfModules.getInstanceName(), vfModules.getInstanceParams(),
+                        cloudConfig, false);
             }
         } else if (bbName.contains(NETWORK)) {
             networks = findNetworksByKey(key, resources);
             String networkId = lookupKeyMap.get(ResourceKey.NETWORK_ID);
             if (networks != null) {
-                this.populateL3Network(networks.getInstanceName(), networks.getModelInfo(), service, bbName,
-                        serviceInstance, lookupKeyMap, networkId, networks.getInstanceParams());
+                this.populateL3Network(executeBB.getRequestId(), networks.getInstanceName(), networks.getModelInfo(),
+                        service, bbName, serviceInstance, lookupKeyMap, networkId, networks.getInstanceParams());
             }
         } else if (bbName.contains("Configuration")) {
             String configurationId = lookupKeyMap.get(ResourceKey.CONFIGURATION_ID);
@@ -1426,8 +1495,9 @@ public class BBInputSetup implements JavaDelegate {
             ConfigurationResourceCustomization configurationCust =
                     findConfigurationResourceCustomization(configurationModelInfo, service);
             if (configurationCust != null) {
-                this.populateConfiguration(configurationModelInfo, service, bbName, serviceInstance, lookupKeyMap,
-                        configurationId, null, executeBB.getConfigurationResourceKeys(), executeBB.getRequestDetails());
+                this.populateConfiguration(executeBB.getRequestId(), configurationModelInfo, service, bbName,
+                        serviceInstance, lookupKeyMap, configurationId, null, executeBB.getConfigurationResourceKeys(),
+                        executeBB.getRequestDetails());
             } else {
                 logger.debug("Could not find a configuration customization with key: {}", key);
             }
@@ -1939,5 +2009,24 @@ public class BBInputSetup implements JavaDelegate {
         return customer;
     }
 
+    protected void updateInstanceName(String requestId, ModelType resourceType, String instanceName) {
+        try {
+            if (instanceName != null) {
+                InfraActiveRequests request = requestsDbClient.getInfraActiveRequestbyRequestId(requestId);
+                if (resourceType.getName(request) == null) {
+                    logger.info("Updating instanceName to: {} in requestDb for requestId: {}", instanceName, requestId);
+                    resourceType.setName(request, instanceName);
+                    requestsDbClient.updateInfraActiveRequests(request);
+                }
+            } else {
+                logger.info("Failed to update instanceName in RequestDb because it was null for requestId: {}",
+                        requestId);
+            }
+        } catch (Exception ex) {
+            logger.error("Unable to update Request db with instanceName for requestId: {} due to error: {}", requestId,
+                    ex.getMessage());
+        }
+    }
+
 
 }