Updated to include all VFModule members
[so.git] / asdc-controller / src / main / java / org / onap / so / asdc / installer / heat / ToscaResourceInstaller.java
index 7951e9b..3a29247 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
  * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -39,7 +41,10 @@ import org.hibernate.exception.LockAcquisitionException;
 import org.onap.sdc.api.notification.IArtifactInfo;
 import org.onap.sdc.api.notification.IResourceInstance;
 import org.onap.sdc.api.notification.IStatusData;
+import org.onap.sdc.tosca.parser.api.IEntityDetails;
 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.onap.sdc.tosca.parser.elements.queries.EntityQuery;
+import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery;
 import org.onap.sdc.tosca.parser.enums.SdcTypes;
 import org.onap.sdc.tosca.parser.impl.SdcPropertyNames;
 import org.onap.sdc.toscaparser.api.CapabilityAssignment;
@@ -51,6 +56,7 @@ import org.onap.sdc.toscaparser.api.Property;
 import org.onap.sdc.toscaparser.api.RequirementAssignment;
 import org.onap.sdc.toscaparser.api.RequirementAssignments;
 import org.onap.sdc.toscaparser.api.elements.Metadata;
+import org.onap.sdc.toscaparser.api.elements.StatefulEntityType;
 import org.onap.sdc.toscaparser.api.functions.GetInput;
 import org.onap.sdc.toscaparser.api.parameters.Input;
 import org.onap.sdc.utils.DistributionStatusEnum;
@@ -59,6 +65,8 @@ import org.onap.so.asdc.client.exceptions.ArtifactInstallerException;
 import org.onap.so.asdc.installer.ASDCElementInfo;
 import org.onap.so.asdc.installer.BigDecimalVersion;
 import org.onap.so.asdc.installer.IVfModuleData;
+import org.onap.so.asdc.installer.PnfResourceStructure;
+import org.onap.so.asdc.installer.ResourceStructure;
 import org.onap.so.asdc.installer.ToscaResourceStructure;
 import org.onap.so.asdc.installer.VfModuleArtifact;
 import org.onap.so.asdc.installer.VfModuleStructure;
@@ -81,6 +89,8 @@ import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
 import org.onap.so.db.catalog.beans.NetworkInstanceGroup;
 import org.onap.so.db.catalog.beans.NetworkResource;
 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
+import org.onap.so.db.catalog.beans.PnfResource;
+import org.onap.so.db.catalog.beans.PnfResourceCustomization;
 import org.onap.so.db.catalog.beans.Service;
 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
 import org.onap.so.db.catalog.beans.SubType;
@@ -106,6 +116,8 @@ import org.onap.so.db.catalog.data.repository.HeatTemplateRepository;
 import org.onap.so.db.catalog.data.repository.InstanceGroupRepository;
 import org.onap.so.db.catalog.data.repository.NetworkResourceCustomizationRepository;
 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
+import org.onap.so.db.catalog.data.repository.PnfCustomizationRepository;
+import org.onap.so.db.catalog.data.repository.PnfResourceRepository;
 import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository;
 import org.onap.so.db.catalog.data.repository.ServiceRepository;
 import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
@@ -121,9 +133,12 @@ import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup;
 import org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository;
 import org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository;
 import org.onap.so.db.request.data.repository.WatchdogServiceModVerIdLookupRepository;
+import org.onap.so.logger.ErrorCode;
 import org.onap.so.logger.MessageEnum;
-import org.onap.so.logger.MsoLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.orm.ObjectOptimisticLockingFailureException;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -133,6 +148,10 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 @Component
 public class ToscaResourceInstaller {
 
+       protected static final String NODES_VRF_ENTRY = "org.openecomp.nodes.VRFEntry";
+
+       protected static final String VLAN_NETWORK_RECEPTOR = "org.openecomp.nodes.VLANNetworkReceptor";
+
        protected static final String ALLOTTED_RESOURCE = "Allotted Resource";
 
        protected static final String MULTI_STAGE_DESIGN = "multi_stage_design";
@@ -149,6 +168,12 @@ public class ToscaResourceInstaller {
 
        protected static final String MSO = "SO";
 
+       protected static final String SDNC_MODEL_NAME = "sdnc_model_name";
+
+       protected static final String SDNC_MODEL_VERSION = "sdnc_model_version";
+
+       private static String CUSTOMIZATION_UUID = "customizationUUID";
+
 
        @Autowired
        protected ServiceRepository serviceRepo;
@@ -220,15 +245,21 @@ public class ToscaResourceInstaller {
        @Autowired
        protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository;
        
-       protected static final MsoLogger logger = MsoLogger.getMsoLogger (MsoLogger.Catalog.ASDC,ToscaResourceInstaller.class);
+       @Autowired
+       protected PnfResourceRepository pnfResourceRepository;
+
+       @Autowired
+       protected PnfCustomizationRepository pnfCustomizationRepository;
+
+       protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceInstaller.class);
 
        public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException {
                boolean status = false;
                VfResourceStructure vfResourceStructure = vfResourceStruct;
                try {
-                   status = vfResourceStructure.isDeployedSuccessfully();
+                       status = vfResourceStructure.isDeployedSuccessfully();
                } catch (RuntimeException e) {
-                   status = false;
+                       status = false;
                }
                try {                                   
                        Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID()); 
@@ -256,15 +287,16 @@ public class ToscaResourceInstaller {
                        }
                        return status;
                } catch (Exception e) {
-                       logger.error(MessageEnum.ASDC_ARTIFACT_CHECK_EXC, "", "", MsoLogger.ErrorCode.SchemaError,
+                       logger
+                               .error("{} {} {}", MessageEnum.ASDC_ARTIFACT_CHECK_EXC.toString(), ErrorCode.SchemaError.getValue(),
                                        "Exception - isResourceAlreadyDeployed");
                        throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
                }
        }
 
        public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException {
-               logger.debug("Entering installTheComponentStatus for distributionId " + iStatus.getDistributionID()
-                               + " and ComponentName " + iStatus.getComponentName());
+               logger.debug("Entering installTheComponentStatus for distributionId {} and ComponentName {}",
+                       iStatus.getDistributionID(), iStatus.getComponentName());
 
                try {
                        WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus(iStatus.getDistributionID(),
@@ -273,13 +305,79 @@ public class ToscaResourceInstaller {
                        watchdogCDStatusRepository.save(cdStatus);
 
                } catch (Exception e) {
-                       logger.debug("Exception caught in installTheComponentStatus " + e.getMessage());
+                       logger.debug("Exception caught in installTheComponentStatus {}", e.getMessage());
                        throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage());
                }
        }
 
+       @Transactional(rollbackFor = {ArtifactInstallerException.class})
+       public void installTheResource(ToscaResourceStructure toscaResourceStruct, ResourceStructure resourceStruct)
+               throws ArtifactInstallerException {
+               if (resourceStruct instanceof VfResourceStructure) {
+                       installTheVfResource(toscaResourceStruct, (VfResourceStructure) resourceStruct);
+               } else if (resourceStruct instanceof PnfResourceStructure) {
+                       installPnfResource(toscaResourceStruct, (PnfResourceStructure) resourceStruct);
+               } else {
+                       logger.warn("Unrecognized resource type");
+               }
+       }
+
+       private void installPnfResource(ToscaResourceStructure toscaResourceStruct, PnfResourceStructure resourceStruct)
+               throws ArtifactInstallerException {
+
+               // PCLO: in case of deployment failure, use a string that will represent
+               // the type of artifact that failed...
+               List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
+               try {
+                       createToscaCsar(toscaResourceStruct);
+                       Service service = createService(toscaResourceStruct, resourceStruct);
+
+                       processResourceSequence(toscaResourceStruct, service);
+                       processPnfResources(toscaResourceStruct, service, resourceStruct);
+                       serviceRepo.save(service);
+
+                       WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(
+                               resourceStruct.getNotification().getDistributionID(), MSO);
+                       status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
+                       watchdogCDStatusRepository.save(status);
+
+                       toscaResourceStruct.setSuccessfulDeployment();
+
+               } catch (Exception e) {
+                       logger.debug("Exception :", e);
+                       WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus(
+                               resourceStruct.getNotification().getDistributionID(), MSO);
+                       status.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR.name());
+                       watchdogCDStatusRepository.save(status);
+                       Throwable dbExceptionToCapture = e;
+                       while (!(dbExceptionToCapture instanceof ConstraintViolationException
+                               || dbExceptionToCapture instanceof LockAcquisitionException)
+                               && (dbExceptionToCapture.getCause() != null)) {
+                               dbExceptionToCapture = dbExceptionToCapture.getCause();
+                       }
+
+                       if (dbExceptionToCapture instanceof ConstraintViolationException
+                               || dbExceptionToCapture instanceof LockAcquisitionException) {
+                               logger.warn("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(),
+                                       resourceStruct.getResourceInstance().getResourceName(),
+                                       resourceStruct.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(),
+                                       "Exception - ASCDC Artifact already deployed", e);
+                       } else {
+                               String elementToLog = (!artifactListForLogging.isEmpty()
+                                       ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
+                                       : "No element listed");
+                               logger.error("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog,
+                                       ErrorCode.DataError.getValue(),
+                                       "Exception caught during installation of " + resourceStruct.getResourceInstance()
+                                               .getResourceName()
+                                               + ". Transaction rollback", e);
+                               throw new ArtifactInstallerException("Exception caught during installation of "
+                                       + resourceStruct.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
+                       }
+               }
+       }
        @Transactional(rollbackFor = { ArtifactInstallerException.class })
-       public void installTheResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct)
+       public void installTheVfResource(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStruct)
                        throws ArtifactInstallerException {             
                VfResourceStructure vfResourceStructure = vfResourceStruct;
                extractHeatInformation(toscaResourceStruct, vfResourceStructure);       
@@ -289,8 +387,7 @@ public class ToscaResourceInstaller {
                List<ASDCElementInfo> artifactListForLogging = new ArrayList<>();
                try {
                        createToscaCsar(toscaResourceStruct);                   
-                       createService(toscaResourceStruct, vfResourceStruct);                   
-                       Service service = toscaResourceStruct.getCatalogService();                              
+                       Service service = createService(toscaResourceStruct, vfResourceStruct);
                        List<NodeTemplate> vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();
                        
                
@@ -336,18 +433,18 @@ public class ToscaResourceInstaller {
 
                        if (dbExceptionToCapture instanceof ConstraintViolationException
                                        || dbExceptionToCapture instanceof LockAcquisitionException) {
-                               logger.warn(MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED,
-                                               vfResourceStructure.getResourceInstance().getResourceName(),
-                                               vfResourceStructure.getNotification().getServiceVersion(), "", MsoLogger.ErrorCode.DataError, "Exception - ASCDC Artifact already deployed", e);
+                               logger.warn("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(),
+                                       vfResourceStructure.getResourceInstance().getResourceName(),
+                                       vfResourceStructure.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(),
+                                       "Exception - ASCDC Artifact already deployed", e);
                        } else {
                                String elementToLog = (!artifactListForLogging.isEmpty()
                                                ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString()
                                                : "No element listed");
-                               logger.error(MessageEnum.ASDC_ARTIFACT_INSTALL_EXC, elementToLog, "", "", MsoLogger.ErrorCode.DataError,
-                                               "Exception caught during installation of "
-                                                               + vfResourceStructure.getResourceInstance().getResourceName()
-                                                               + ". Transaction rollback",
-                                               e);
+                               logger.error("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog,
+                                       ErrorCode.DataError.getValue(),
+                                       "Exception caught during installation of " + vfResourceStructure.getResourceInstance().getResourceName()
+                                               + ". Transaction rollback", e);
                                throw new ArtifactInstallerException("Exception caught during installation of "
                                                + vfResourceStructure.getResourceInstance().getResourceName() + ". Transaction rollback.", e);
                        }
@@ -420,8 +517,6 @@ public class ToscaResourceInstaller {
                logger.debug(" resourceSeq for service uuid(" + service.getModelUUID() + ") : " + resourceSeqStr);
        }
 
-       private static String CUSTOMIZATION_UUID = "customizationUUID";
-
        private static String getValue(Object value, List<Input> servInputs) {
                String output = null;
                if(value instanceof Map) {
@@ -478,42 +573,42 @@ public class ToscaResourceInstaller {
                }
        }
 
-    protected void processNetworks (ToscaResourceStructure toscaResourceStruct,
-                                    Service service) throws ArtifactInstallerException {
-        List <NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper ().getServiceVlList ();
+       protected void processNetworks (ToscaResourceStructure toscaResourceStruct,
+                                                                       Service service) throws ArtifactInstallerException {
+               List <NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper ().getServiceVlList ();
 
                if (nodeTemplatesVLList != null) {
                        for (NodeTemplate vlNode : nodeTemplatesVLList) {
-                String networkResourceModelName = vlNode.getMetaData ().getValue (SdcPropertyNames.PROPERTY_NAME_NAME);
-
-                TempNetworkHeatTemplateLookup tempNetworkLookUp =
-                                                                tempNetworkLookupRepo.findFirstBynetworkResourceModelName (networkResourceModelName);
-
-                if (tempNetworkLookUp != null) {
-                    HeatTemplate heatTemplate =
-                                              heatRepo.findByArtifactUuid (tempNetworkLookUp.getHeatTemplateArtifactUuid ());
-                    if (heatTemplate != null) {
-                        NetworkResourceCustomization networkCustomization =
-                                                                          createNetwork (vlNode,
-                                                                                         toscaResourceStruct,
-                                                                                         heatTemplate,
-                                                                                         tempNetworkLookUp.getAicVersionMax (),
-                                                                                         tempNetworkLookUp.getAicVersionMin (),
-                                                                                         service);
-                        service.getNetworkCustomizations ().add (networkCustomization);
-                    } else {
-                        throw new ArtifactInstallerException ("No HeatTemplate found for artifactUUID: "
-                                                              + tempNetworkLookUp.getHeatTemplateArtifactUuid ());
+                               String networkResourceModelName = vlNode.getMetaData ().getValue (SdcPropertyNames.PROPERTY_NAME_NAME);
+
+                               TempNetworkHeatTemplateLookup tempNetworkLookUp =
+                                                                                                                               tempNetworkLookupRepo.findFirstBynetworkResourceModelName (networkResourceModelName);
+
+                               if (tempNetworkLookUp != null) {
+                                       HeatTemplate heatTemplate =
+                                                                                         heatRepo.findByArtifactUuid (tempNetworkLookUp.getHeatTemplateArtifactUuid ());
+                                       if (heatTemplate != null) {
+                                               NetworkResourceCustomization networkCustomization =
+                                                                                                                                                 createNetwork (vlNode,
+                                                                                                                                                                                toscaResourceStruct,
+                                                                                                                                                                                heatTemplate,
+                                                                                                                                                                                tempNetworkLookUp.getAicVersionMax (),
+                                                                                                                                                                                tempNetworkLookUp.getAicVersionMin (),
+                                                                                                                                                                                service);
+                                               service.getNetworkCustomizations ().add (networkCustomization);
+                                       } else {
+                                               throw new ArtifactInstallerException ("No HeatTemplate found for artifactUUID: "
+                                                                                                                         + tempNetworkLookUp.getHeatTemplateArtifactUuid ());
                                        }
                                } else {
-                    NetworkResourceCustomization networkCustomization = createNetwork (vlNode,
-                                                                                       toscaResourceStruct,
-                                                                                       null,
-                                                                                       null,
-                                                                                       null,
-                                                                                       service);
-                    service.getNetworkCustomizations().add (networkCustomization);
-                    logger.debug ("No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
+                                       NetworkResourceCustomization networkCustomization = createNetwork (vlNode,
+                                                                                                                                                                          toscaResourceStruct,
+                                                                                                                                                                          null,
+                                                                                                                                                                          null,
+                                                                                                                                                                          null,
+                                                                                                                                                                          service);
+                                       service.getNetworkCustomizations().add (networkCustomization);
+                                       logger.debug ("No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
                                                                        + networkResourceModelName);
                                }                                       
                                
@@ -530,6 +625,62 @@ public class ToscaResourceInstaller {
                        }
                }
        }
+       
+       
+       protected ConfigurationResource getConfigurationResource(NodeTemplate nodeTemplate) {
+               Metadata metadata = nodeTemplate.getMetaData();
+               ConfigurationResource configResource = new ConfigurationResource();
+               configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
+               configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
+               configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
+               configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
+               configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
+               configResource.setToscaNodeType(nodeTemplate.getType());
+               return configResource;
+       }
+       
+       protected ConfigurationResourceCustomization getConfigurationResourceCustomization(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, 
+                       ServiceProxyResourceCustomization spResourceCustomization ) {
+               Metadata metadata = nodeTemplate.getMetaData();
+               
+               ConfigurationResource configResource = getConfigurationResource(nodeTemplate);
+               
+               ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
+               
+               Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
+               
+               configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
+               configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
+               
+               configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
+               configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
+               configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
+               configCustomizationResource.setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID());
+       
+               configCustomizationResource.setConfigurationResource(configResource);
+               configResourceCustomizationSet.add(configCustomizationResource);
+
+               configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);   
+               return configCustomizationResource;
+       }
+       
+       
+       protected Optional<ConfigurationResourceCustomization> getVnrNodeTemplate(List<NodeTemplate> configurationNodeTemplatesList,  
+                       ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) {
+               Optional<ConfigurationResourceCustomization> configurationResourceCust = Optional.empty();
+               for (NodeTemplate nodeTemplate : configurationNodeTemplatesList) {
+                       StatefulEntityType entityType = nodeTemplate.getTypeDefinition();
+                       String type = entityType.getType();
+                       
+                       if(VLAN_NETWORK_RECEPTOR.equals(type)) {
+                               configurationResourceCust= Optional.of(getConfigurationResourceCustomization(nodeTemplate, 
+                                               toscaResourceStructure,spResourceCustomization));
+                               break;
+                       }
+               }
+               
+               return configurationResourceCust;
+       }
                
        protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
                
@@ -544,28 +695,28 @@ public class ToscaResourceInstaller {
                
                if (serviceProxyResourceList != null) {
                        for (NodeTemplate spNode : serviceProxyResourceList) {
-                               serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct);
-                               
-                               ServiceProxyResourceCustomization serviceProxyResource = findExistingServiceProxyResource(serviceProxyList, serviceProxy.getModelCustomizationUUID());
-                               
-                               if(serviceProxyResource == null){
-                               
+                               serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct);                                                                
                                serviceProxyList.add(serviceProxy);
-
+                               Optional<ConfigurationResourceCustomization> vnrResourceCustomization = getVnrNodeTemplate(configurationNodeTemplatesList,toscaResourceStruct,serviceProxy);
+                               
                                for (NodeTemplate configNode : configurationNodeTemplatesList) {
                                                                                
                                                List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
                                                for (RequirementAssignment requirement :  requirementsList) {
                                                        if (requirement.getNodeTemplateName().equals(spNode.getName())) {
-                                                               ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy);
-                                                                                                                               
-                                                               configurationResourceList.add(configurationResource);
+                                                               ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy, vnrResourceCustomization);
+                                                               
+                                                               Optional<ConfigurationResourceCustomization> matchingObject = configurationResourceList.stream()
+                                                                               .filter(configurationResourceCustomization -> configNode.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID).equals(configurationResource.getModelCustomizationUUID()))
+                                                                               .findFirst();
+                                                               if(!matchingObject.isPresent()){                                                                                                                                        
+                                                                       configurationResourceList.add(configurationResource);
+                                                               }
+                                                               
                                                                break;
                                                        }
                                                }
                                }
-                               
-                               }
        
                        }
                }
@@ -638,6 +789,123 @@ public class ToscaResourceInstaller {
                }
        }
        
+       /**
+        * This is used to process the PNF specific resource, including resource and resource_customization. {@link
+        * IEntityDetails} based API is used to retrieve information. Please check {@link ISdcCsarHelper} for details.
+        */
+       protected void processPnfResources(ToscaResourceStructure toscaResourceStruct, Service service,
+               PnfResourceStructure resourceStructure) throws Exception {
+               logger.info("Processing PNF resource: {}", resourceStructure.getResourceInstance().getResourceUUID());
+
+               ISdcCsarHelper sdcCsarHelper = toscaResourceStruct.getSdcCsarHelper();
+               EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.PNF).build();
+               TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build();
+
+               List<IEntityDetails> entityDetailsList = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false);
+               for (IEntityDetails entityDetails : entityDetailsList) {
+                       Metadata metadata = entityDetails.getMetadata();
+                       String customizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
+                       String modelUuid = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
+                       String notifCustomizationUUID = resourceStructure.getResourceInstance().getResourceCustomizationUUID();
+                       if (customizationUUID != null && customizationUUID.equals(notifCustomizationUUID)) {
+                               logger.info("Resource customization UUID: {} is the same as notified resource customizationUUID: {}",
+                                       customizationUUID, notifCustomizationUUID);
+
+                               if (checkExistingPnfResourceCutomization(customizationUUID)) {
+                                       logger.info("Resource customization UUID: {} already deployed", customizationUUID);
+                               } else {
+                                       PnfResource pnfResource = findExistingPnfResource(service, modelUuid);
+                                       if (pnfResource == null) {
+                                               pnfResource = createPnfResource(entityDetails);
+                                       }
+                                       PnfResourceCustomization pnfResourceCustomization = createPnfResourceCustomization(entityDetails,
+                                               pnfResource);
+                                       pnfResource.getPnfResourceCustomizations().add(pnfResourceCustomization);
+                                       toscaResourceStruct.setPnfResourceCustomization(pnfResourceCustomization);
+                                       service.getPnfCustomizations().add(pnfResourceCustomization);
+                               }
+                       } else {
+                               logger
+                                       .warn("Resource customization UUID: {} is NOT the same as notified resource customizationUUID: {}",
+                                               customizationUUID, notifCustomizationUUID);
+                       }
+               }
+       }
+
+       private PnfResource findExistingPnfResource(Service service, String modelUuid) {
+               PnfResource pnfResource = null;
+               for (PnfResourceCustomization pnfResourceCustomization : service.getPnfCustomizations()) {
+                       if (pnfResourceCustomization.getPnfResources() != null && pnfResourceCustomization.getPnfResources()
+                               .getModelUUID().equals(modelUuid)) {
+                               pnfResource = pnfResourceCustomization.getPnfResources();
+                       }
+               }
+               if (pnfResource == null) {
+                       pnfResource = pnfResourceRepository.findById(modelUuid).orElse(pnfResource);
+               }
+               return pnfResource;
+       }
+
+       private boolean checkExistingPnfResourceCutomization(String customizationUUID) {
+               return pnfCustomizationRepository.findById(customizationUUID).isPresent();
+       }
+
+       /**
+        * Construct the {@link PnfResource} from {@link IEntityDetails} object.
+        */
+       private PnfResource createPnfResource(IEntityDetails entity) {
+               PnfResource pnfResource = new PnfResource();
+               Metadata metadata = entity.getMetadata();
+               pnfResource.setModelInvariantUUID(
+                       testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
+               pnfResource.setModelName(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
+               pnfResource.setModelUUID(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
+               pnfResource.setModelVersion(
+                       testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
+               pnfResource.setDescription(
+                       testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
+               pnfResource.setCategory(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY)));
+               pnfResource.setSubCategory(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
+               pnfResource.setToscaNodeType(entity.getToscaType());
+               return pnfResource;
+       }
+
+       /**
+        * Construct the {@link PnfResourceCustomization} from {@link IEntityDetails} object.
+        */
+       private PnfResourceCustomization createPnfResourceCustomization(IEntityDetails entityDetails,
+               PnfResource pnfResource) {
+
+               PnfResourceCustomization pnfResourceCustomization = new PnfResourceCustomization();
+               Metadata metadata = entityDetails.getMetadata();
+               Map<String, Property> properties = entityDetails.getProperties();
+               pnfResourceCustomization
+                       .setModelCustomizationUUID(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
+               pnfResourceCustomization.setModelInstanceName(entityDetails.getName());
+               pnfResourceCustomization
+                       .setNfFunction(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
+               pnfResourceCustomization.setNfNamingCode(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFCODE)));
+               pnfResourceCustomization.setNfRole(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFROLE)));
+               pnfResourceCustomization.setNfType(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
+               pnfResourceCustomization.setMultiStageDesign(getStringValue(properties.get(MULTI_STAGE_DESIGN)));
+               pnfResourceCustomization.setBlueprintName(getStringValue(properties.get(SDNC_MODEL_NAME)));
+               pnfResourceCustomization.setBlueprintVersion(getStringValue(properties.get(SDNC_MODEL_VERSION)));
+
+               pnfResourceCustomization.setPnfResources(pnfResource);
+
+               return pnfResourceCustomization;
+       }
+
+       /**
+        * Get value from {@link Property} and cast to String value. Return empty String if property is null value.
+        */
+       private String getStringValue(Property property) {
+               if (null == property) {
+                       return "";
+               }
+               Object value = property.getValue();
+               return String.valueOf(value);
+       }
        
        protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure,
                        Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory) throws Exception {
@@ -655,7 +923,7 @@ public class ToscaResourceInstaller {
                        
                        // Make sure the VF ResourceCustomizationUUID from the notification and tosca customizations match before comparing their VF Modules UUID's
                        logger.debug("Checking if Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + 
-                                                  " matches Tosca VF Customization UUID: " +  vfCustomizationUUID);
+                                                          " matches Tosca VF Customization UUID: " +  vfCustomizationUUID);
                        
                        if(vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())){
                                
@@ -671,14 +939,14 @@ public class ToscaResourceInstaller {
                                        logger.debug("vfModuleStructure:" + vfModuleStructure.toString());
                                        List<org.onap.sdc.toscaparser.api.Group> vfGroups = toscaResourceStruct
                                                        .getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID);
-                                       IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();     
+                                       IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata();                                             
                                        
                                        logger.debug("Comparing Vf_Modules_Metadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID());
                                        
                                        Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream()
                                                        .peek(group -> logger.debug("To Csar Group VFModuleModelCustomizationUUID " + group.getMetadata().getValue("vfModuleModelCustomizationUUID")))
-                                                   .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID()))
-                                                   .findFirst();
+                                                       .filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID()))
+                                                       .findFirst();
                                        if(matchingObject.isPresent()){
                                                VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct, 
                                                                                                                                                                                         vfResourceStructure,vfMetadata, vnfResource, service, existingCvnfcSet, existingVnfcSet);
@@ -690,19 +958,28 @@ public class ToscaResourceInstaller {
                                service.getVnfCustomizations().add(vnfResource);
                        } else{
                                logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " +
-                                                    "Tosca VF Customization UUID: " +  vfCustomizationUUID);
+                                                        "Tosca VF Customization UUID: " +  vfCustomizationUUID);
                        }
                }
        }
 
-       public void processWatchdog(String distributionId, String servideUUID) {
-               WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId,servideUUID);
+       public void processWatchdog(String distributionId, String servideUUID, Optional<String> distributionNotification,
+                       String consumerId) {
+               WatchdogServiceModVerIdLookup modVerIdLookup = new WatchdogServiceModVerIdLookup(distributionId, servideUUID,
+                               distributionNotification, consumerId);
                watchdogModVerIdLookupRepository.saveAndFlush(modVerIdLookup);
                
-               WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
-               watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
+               try{
+               
+                       WatchdogDistributionStatus distributionStatus = new WatchdogDistributionStatus(distributionId);
+                       watchdogDistributionStatusRepository.saveAndFlush(distributionStatus);
+                       
+               } catch(ObjectOptimisticLockingFailureException e){
+                       logger.debug("ObjectOptimisticLockingFailureException in processWatchdog : " + e.toString());
+                       throw e;
+               }
        }
-
+       
        protected void extractHeatInformation(ToscaResourceStructure toscaResourceStruct,
                        VfResourceStructure vfResourceStructure) {
                for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) {
@@ -728,10 +1005,9 @@ public class ToscaResourceInstaller {
                                break;
                        case ASDCConfiguration.HEAT_NET:
                        case ASDCConfiguration.OTHER:
-                               logger.warn(MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT,
-                                               vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:"
-                                                               + vfModuleArtifact.getArtifactInfo().getArtifactName() + ")",
-                                               "", "", MsoLogger.ErrorCode.DataError, "Artifact type not supported");
+                               logger.warn("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT.toString(),
+                                       vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:" + vfModuleArtifact.getArtifactInfo()
+                                               .getArtifactName() + ")", ErrorCode.DataError.getValue(), "Artifact type not supported");
                                break;
                        default:
                                break;
@@ -877,9 +1153,7 @@ public class ToscaResourceInstaller {
        }
 
        protected Service createService(ToscaResourceStructure toscaResourceStructure,
-                       VfResourceStructure vfResourceStructure) {
-
-               toscaResourceStructure.getServiceMetadata();
+                       ResourceStructure resourceStructure) {
 
                Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
 
@@ -893,14 +1167,15 @@ public class ToscaResourceInstaller {
 
                        service.setServiceType(serviceMetadata.getValue("serviceType"));
                        service.setServiceRole(serviceMetadata.getValue("serviceRole"));
+                       service.setCategory(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
 
                        service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
                        service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
                        service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
                        service.setEnvironmentContext(serviceMetadata.getValue("environmentContext"));
 
-                       if (vfResourceStructure != null) 
-                               service.setWorkloadContext(vfResourceStructure.getNotification().getWorkloadContext());
+                       if (resourceStructure != null) 
+                               service.setWorkloadContext(resourceStructure.getNotification().getWorkloadContext());
                                                
                        service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
                        service.setCsar(toscaResourceStructure.getCatalogToscaCsar());                  
@@ -928,7 +1203,12 @@ public class ToscaResourceInstaller {
                spCustomizationResource.setModelCustomizationUUID(spMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
                spCustomizationResource.setModelInstanceName(nodeTemplate.getName());
                spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
-               spCustomizationResource.setSourceService(service);
+               
+               String sourceServiceUUID = spMetadata.getValue("sourceModelUuid");
+               
+               Service sourceService = serviceRepo.findOneByModelUUID(sourceServiceUUID);      
+               
+               spCustomizationResource.setSourceService(sourceService);
                spCustomizationResource.setToscaNodeType(nodeTemplate.getType());
                serviceProxyCustomizationSet.add(spCustomizationResource);
 
@@ -938,32 +1218,26 @@ public class ToscaResourceInstaller {
                return spCustomizationResource;
        }
        
-       protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) {
+       protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, 
+                       ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization,
+                       Optional<ConfigurationResourceCustomization> vnrResourceCustomization) {
 
-               Metadata metadata = nodeTemplate.getMetaData();
-               
-               ConfigurationResource configResource = new ConfigurationResource();
-               
-               configResource.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
-               configResource.setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
-               configResource.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
-               configResource.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
-               configResource.setDescription(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
-               configResource.setToscaNodeType(nodeTemplate.getType());
+               ConfigurationResourceCustomization configCustomizationResource = getConfigurationResourceCustomization(nodeTemplate, 
+                               toscaResourceStructure,spResourceCustomization);
                
-               ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
+               ConfigurationResource configResource = getConfigurationResource(nodeTemplate);
                
                Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
                
-               configCustomizationResource.setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
-               configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
-               
-               configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
-               configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
-               configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
-               configCustomizationResource.setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID());
-               configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
+               StatefulEntityType entityType = nodeTemplate.getTypeDefinition();
+               String type = entityType.getType();
+               
+               if(NODES_VRF_ENTRY.equals(type)) {
+                       configCustomizationResource.setConfigResourceCustomization(vnrResourceCustomization.orElse(null));
+               }
+                       
                configCustomizationResource.setConfigurationResource(configResource);
+               
                configResourceCustomizationSet.add(configCustomizationResource);
 
                configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);   
@@ -975,7 +1249,7 @@ public class ToscaResourceInstaller {
                return configCustomizationResource;
        }
        
-       protected ConfigurationResourceCustomization createFabricConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure) {
+       protected ConfigurationResource createFabricConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure) {
                
                Metadata fabricMetadata = nodeTemplate.getMetaData();
                
@@ -988,23 +1262,7 @@ public class ToscaResourceInstaller {
                configResource.setDescription(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
                configResource.setToscaNodeType(nodeTemplate.getType());
                
-               ConfigurationResourceCustomization configCustomizationResource = new ConfigurationResourceCustomization();
-               
-               Set<ConfigurationResourceCustomization> configResourceCustomizationSet = new HashSet<>();
-               
-               configCustomizationResource.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
-               configCustomizationResource.setModelInstanceName(nodeTemplate.getName());
-               
-               configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "function"));
-               configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "role"));
-               configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "type"));
-               configCustomizationResource.setConfigResourceCustomization(configCustomizationResource);
-               configCustomizationResource.setConfigurationResource(configResource);
-               configResourceCustomizationSet.add(configCustomizationResource);
-
-               configResource.setConfigurationResourceCustomization(configResourceCustomizationSet);
-               
-               return configCustomizationResource;
+               return configResource;
        }
 
        protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) {
@@ -1055,7 +1313,31 @@ public class ToscaResourceInstaller {
                        ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,Service service) {
                
                NetworkResourceCustomization networkResourceCustomization=networkCustomizationRepo.findOneByModelCustomizationUUID(networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
-                               if(networkResourceCustomization==null){
+                               
+               boolean networkUUIDsMatch = true;
+               // Check to make sure the NetworkResourceUUID on the Customization record matches the NetworkResourceUUID from the distribution.  
+               // If not we'll update the Customization record with latest from the distribution
+               if(networkResourceCustomization != null){
+                       String existingNetworkModelUUID = networkResourceCustomization.getNetworkResource().getModelUUID();
+                       String latestNetworkModelUUID = networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
+                       
+                       if(!existingNetworkModelUUID.equals(latestNetworkModelUUID)){
+                               networkUUIDsMatch = false;
+                       }
+               
+               }
+
+               if (networkResourceCustomization!=null && !networkUUIDsMatch){
+                       
+                       NetworkResource networkResource = createNetworkResource(networkNodeTemplate, toscaResourceStructure, heatTemplate,
+                                       aicMax, aicMin);
+                       
+                       networkResourceCustomization.setNetworkResource(networkResource);                       
+                                       
+                       networkCustomizationRepo.saveAndFlush(networkResourceCustomization);
+                       
+               }
+               else if(networkResourceCustomization==null){
                        networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate,
                                        toscaResourceStructure);
                                        
@@ -1067,7 +1349,8 @@ public class ToscaResourceInstaller {
 
                                        networkResource.addNetworkResourceCustomization(networkResourceCustomization);          
                                        networkResourceCustomization.setNetworkResource(networkResource);
-                               }
+               }
+               
                return networkResourceCustomization;
        }
        
@@ -1214,16 +1497,32 @@ public class ToscaResourceInstaller {
                        crInstanceGroupCustomization.setModelCustomizationUUID(
                                        networkNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
                
-                       String quantityName = instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
-                       String fixedQuantity = quantityName.replace("NetworkCollection", "Fixed");
-                       if (toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
-                                       fixedQuantity + "_quantity") != null) {
-
-                               crInstanceGroupCustomization.setSubInterfaceNetworkQuantity(Integer.parseInt(
-                                               toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
-                                                               fixedQuantity + "_quantity"))); 
+                       // Loop through the template policy to find the subinterface_network_quantity property name.  Then extract the value for it.
+                       List<Policy> policyList = toscaResourceStructure.getSdcCsarHelper().getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(networkNodeTemplate, "org.openecomp.policies.scaling.Fixed");
+                       
+                       if(policyList != null){
+                               for(Policy policy : policyList){
+                                       for(String policyNetworkCollection : policy.getTargets()){
+                                               
+                                               if(policyNetworkCollection.equalsIgnoreCase(group.getName())){
+                                               
+                                                       Map<String, Object> propMap = policy.getPolicyProperties();
+                                       
+                                                       if(propMap.get("quantity") != null){
+                                                                                                                               
+                                                               String quantity = toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate, getPropertyInput(propMap.get("quantity").toString())); 
+                                       
+                                                               if(quantity != null){
+                                                                       crInstanceGroupCustomization.setSubInterfaceNetworkQuantity(Integer.parseInt(quantity));
+                                                               }
+                                                                                               
+                                                       }
+                                       
+                                          }
+                                       }
+                               }       
                        }
-               
+                                       
                        crInstanceGroupCustomization.setDescription(
                                        toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(networkNodeTemplate,
                                                        instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)
@@ -1240,7 +1539,6 @@ public class ToscaResourceInstaller {
 
                        networkInstanceGroupList.add(networkInstanceGroup);
 
-               //}
 
                toscaResourceStructure.setCatalogNetworkInstanceGroup(networkInstanceGroupList);
 
@@ -1361,7 +1659,7 @@ public class ToscaResourceInstaller {
 
        }
                
-       protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate nodeTemplate,
+       protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate vfTemplate,
                        ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
                        IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, Set<CvnfcCustomization> existingCvnfcSet, Set<VnfcCustomization> existingVnfcSet) {
                
@@ -1369,7 +1667,7 @@ public class ToscaResourceInstaller {
                                vfModuleData.getVfModuleModelCustomizationUUID());
                if(vfModuleCustomization == null){              
                        VfModule vfModule = findExistingVfModule(vnfResource,
-                                       nodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
+                                       vfTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID));
                        Metadata vfMetadata = group.getMetadata();
                        if(vfModule==null)
                                vfModule=createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata);
@@ -1391,15 +1689,28 @@ public class ToscaResourceInstaller {
                Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizations = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>();                
                Set<CvnfcCustomization> cvnfcCustomizations = new HashSet<CvnfcCustomization>();
                Set<VnfcCustomization> vnfcCustomizations = new HashSet<VnfcCustomization>();
-
+               
+               // Only set the CVNFC if this vfModule group is a member of it.  
+               List<NodeTemplate> groupMembers = toscaResourceStructure.getSdcCsarHelper().getMembersOfVfModule(vfTemplate, group); 
+               String vfModuleMemberName = null;
+               
                // Extract CVFC lists
-               List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CVFC);
+               List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(vfTemplate, SdcTypes.CVFC);
                                                
                for(NodeTemplate cvfcTemplate : cvfcList) {
-                                                                       
-                       CvnfcCustomization existingCvnfcCustomization = findExistingCvfc(existingCvnfcSet, cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
                        
-                       if(existingCvnfcCustomization == null){
+                       boolean cvnfcVfModuleNameMatch = false;
+                       
+                       for(NodeTemplate node : groupMembers){          
+                               vfModuleMemberName = node.getName();
+                               
+                               if(vfModuleMemberName.equalsIgnoreCase(cvfcTemplate.getName())){
+                                       cvnfcVfModuleNameMatch = true;
+                                       break;
+                               }
+                       }
+                       
+                       if(vfModuleMemberName != null && cvnfcVfModuleNameMatch){
                        
                        //Extract associated VFC - Should always be just one
                        List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC);
@@ -1410,6 +1721,12 @@ public class ToscaResourceInstaller {
                                VnfcCustomization existingVnfcCustomization = null;
                                
                                existingVnfcCustomization = findExistingVfc(existingVnfcSet, vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
+                               
+                               if(existingVnfcCustomization == null){
+                                       vnfcCustomization = new VnfcCustomization();
+                               } else {
+                                       vnfcCustomization = existingVnfcCustomization;
+                               }
                                        
                                // Only Add Abstract VNFC's to our DB, ignore all others
                                if(existingVnfcCustomization == null && vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")){
@@ -1432,36 +1749,40 @@ public class ToscaResourceInstaller {
                        // This check is needed incase the VFC subcategory is something other than Abstract.  In that case we want to skip adding that record to our DB.
                        if(vnfcCustomization.getModelCustomizationUUID() != null){
                                
-                               CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
-                               cvnfcCustomization.setModelCustomizationUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
-                               cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName());
-                               cvnfcCustomization.setModelInvariantUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
-                               cvnfcCustomization.setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
-                               cvnfcCustomization.setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
+                                       CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
        
-                               cvnfcCustomization.setModelVersion(
-                                               testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
-                               cvnfcCustomization.setDescription(
-                                               testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
-                               cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType()));
-                               
-                               if(existingVnfcCustomization != null){
-                                       cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization);
-                               }else{
-                                       cvnfcCustomization.setVnfcCustomization(vnfcCustomization);
-                               }
-                               
-                               cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization);
-                               cvnfcCustomization.setVnfResourceCustomization(vnfResource);                                    
-                               
-                               cvnfcCustomizations.add(cvnfcCustomization);
-                               existingCvnfcSet.add(cvnfcCustomization);
+                                       cvnfcCustomization = new CvnfcCustomization();
+                                       cvnfcCustomization.setModelCustomizationUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
+                                       cvnfcCustomization.setModelInstanceName(cvfcTemplate.getName());
+                                       cvnfcCustomization.setModelInvariantUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
+                                       cvnfcCustomization.setModelName(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
+                                       cvnfcCustomization.setModelUUID(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
+               
+                                       cvnfcCustomization.setModelVersion(
+                                                       testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
+                                       cvnfcCustomization.setDescription(
+                                                       testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
+                                       cvnfcCustomization.setToscaNodeType(testNull(cvfcTemplate.getType()));
+                                       
+                                       if(existingVnfcCustomization != null){
+                                               cvnfcCustomization.setVnfcCustomization(existingVnfcCustomization);
+                                       }else{
+                                               cvnfcCustomization.setVnfcCustomization(vnfcCustomization);
+                                       }
+                                       
+                                       cvnfcCustomization.setNfcFunction(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_function"));
+                                       cvnfcCustomization.setNfcNamingCode(toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(cvfcTemplate, "nfc_naming_code"));
+                                       cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization);
+                                       cvnfcCustomization.setVnfResourceCustomization(vnfResource);
+       
+                                       cvnfcCustomizations.add(cvnfcCustomization);
+                                       existingCvnfcSet.add(cvnfcCustomization);                               
                        
                        //*****************************************************************************************************************************************
                        //* Extract Fabric Configuration
                        //*****************************************************************************************************************************************
                        
-                       List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CONFIGURATION);
+                       List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(vfTemplate, SdcTypes.CONFIGURATION);
                                                                
                        for(NodeTemplate fabricTemplate : fabricConfigList) {
                                                                                
@@ -1471,30 +1792,23 @@ public class ToscaResourceInstaller {
                                                                
                                if(existingConfig == null){
                                        
-                                       ConfigurationResourceCustomization fabricConfigCustomization = createFabricConfiguration(fabricTemplate, toscaResourceStructure);
+                                       fabricConfig = createFabricConfiguration(fabricTemplate, toscaResourceStructure);
                                        
-                                       fabricConfig = fabricConfigCustomization.getConfigurationResource();
-                                       
-                                       service.getConfigurationCustomizations().add(fabricConfigCustomization);
                                }else {
                                        fabricConfig = existingConfig;
-                               }
-                               
+                               }                               
                                
                                VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = createVfCnvfConfigCustomization(fabricTemplate, toscaResourceStructure, 
-                                                                                                                                                          vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig);
-                               
+                                                                                                                                                          vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig, vfTemplate, vfModuleMemberName);
                                vnfVfmoduleCvnfcConfigurationCustomizations.add(vnfVfmoduleCvnfcConfigurationCustomization);
                        }
-                       
+                       cvnfcCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations);
                        }
                        
                   }
                        
                  }
-                       
                } 
-               
                vfModuleCustomization.setCvnfcCustomization(cvnfcCustomizations);
                vfModuleCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations);
                
@@ -1502,12 +1816,11 @@ public class ToscaResourceInstaller {
        }
        
        protected VnfVfmoduleCvnfcConfigurationCustomization createVfCnvfConfigCustomization(NodeTemplate fabricTemplate, ToscaResourceStructure toscaResourceStruct, 
-            VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization,
-            ConfigurationResource configResource) {
+                       VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization,
+                       ConfigurationResource configResource, NodeTemplate vfTemplate, String vfModuleMemberName) {
 
-               Metadata fabricMetadata = fabricTemplate.getMetaData();
-               
-               
+               Metadata fabricMetadata = fabricTemplate.getMetaData(); 
+                               
                VnfVfmoduleCvnfcConfigurationCustomization vfModuleToCvnfc = new VnfVfmoduleCvnfcConfigurationCustomization();
                
                vfModuleToCvnfc.setConfigurationResource(configResource);
@@ -1516,20 +1829,30 @@ public class ToscaResourceInstaller {
                vfModuleToCvnfc.setModelInstanceName(fabricTemplate.getName());
                vfModuleToCvnfc.setVfModuleCustomization(vfModuleCustomization);
                vfModuleToCvnfc.setVnfResourceCustomization(vnfResource);
-               vfModuleToCvnfc.setPolicyName(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "name"));
                
-               List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper().getPoliciesOfTarget(fabricTemplate);
+               List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper().getPoliciesOfOriginOfNodeTemplateByToscaPolicyType(vfTemplate, "org.openecomp.policies.External");
                
                if(policyList != null){
                        for(Policy policy : policyList){
-                               vfModuleToCvnfc.setPolicyName(policy.getName());
-                       }
+                               
+                               for(String policyCvfcTarget : policy.getTargets()){
+                                       
+                                       if(policyCvfcTarget.equalsIgnoreCase(vfModuleMemberName)){
+                               
+                                               Map<String, Object> propMap = policy.getPolicyProperties();
+
+                                               if(propMap.get("type").toString().equalsIgnoreCase("Fabric Policy")){
+                                                       vfModuleToCvnfc.setPolicyName(propMap.get("name").toString());
+                                               }
+                                       }
+                               }
+                       }                       
                }
                
-               vfModuleToCvnfc.setConfigurationFunction(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
-               vfModuleToCvnfc.setConfigurationRole(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE));
-               vfModuleToCvnfc.setConfigurationType(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
-               
+               vfModuleToCvnfc.setConfigurationFunction(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "function"));
+               vfModuleToCvnfc.setConfigurationRole(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "role"));
+               vfModuleToCvnfc.setConfigurationType(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "type"));
+                       
                return vfModuleToCvnfc;
        }
                
@@ -1546,21 +1869,7 @@ public class ToscaResourceInstaller {
                
                return configResource;
        }
-       
-       protected ServiceProxyResourceCustomization findExistingServiceProxyResource(List<ServiceProxyResourceCustomization> serviceProxyList, String modelCustomizationUUID) {
-               ServiceProxyResourceCustomization serviceProxyResourceCustomization = null;
-               for(ServiceProxyResourceCustomization serviceProxyResourceCustom : serviceProxyList){
-                       if (serviceProxyResourceCustom != null
-                                       && serviceProxyResourceCustom.getModelCustomizationUUID().equals(modelCustomizationUUID)) {
-                               serviceProxyResourceCustomization = serviceProxyResourceCustom;
-                       }
-               }
-               if(serviceProxyResourceCustomization==null)
-                       serviceProxyResourceCustomization = serviceProxyCustomizationRepo.findResourceByModelCustomizationUUID(modelCustomizationUUID);
                
-               return serviceProxyResourceCustomization;
-       }
-       
        protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource,
                        String vfModuleModelCustomizationUUID) {
                VfModuleCustomization vfModuleCustomization = null;
@@ -1664,7 +1973,7 @@ public class ToscaResourceInstaller {
        protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure,
                        VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization,
                        Metadata vfMetadata) {
-               
+                               
                Optional<VfModuleStructure> matchingObject = vfResourceStructure.getVfModuleStructure().stream()
                                .filter(vfModuleStruct -> vfModuleStruct.getVfModuleMetadata().getVfModuleModelUUID()
                                                .equalsIgnoreCase(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata,
@@ -1817,6 +2126,12 @@ public class ToscaResourceInstaller {
                vnfResourceCustomization.setMultiStageDesign(toscaResourceStructure.getSdcCsarHelper()
                                .getNodeTemplatePropertyLeafValue(vfNodeTemplate, MULTI_STAGE_DESIGN));
 
+               vnfResourceCustomization.setBlueprintName(testNull(toscaResourceStructure.getSdcCsarHelper()
+                       .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SDNC_MODEL_NAME)));
+
+               vnfResourceCustomization.setBlueprintVersion(testNull(toscaResourceStructure.getSdcCsarHelper()
+                       .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SDNC_MODEL_VERSION)));
+
                vnfResourceCustomization.setVnfResources(vnfResource);
                vnfResourceCustomization.setAvailabilityZoneMaxCount(Integer.getInteger(
                                vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_AVAILABILITYZONECOUNT)));  
@@ -2029,6 +2344,20 @@ public class ToscaResourceInstaller {
                                + vfModuleStructure.getVfModuleMetadata().getVfModuleModelName();
        }
        
+       protected String getPropertyInput(String propertyName){
+       
+               String inputName = new String();
+               
+               if (propertyName != null) { 
+                       int getInputIndex = propertyName.indexOf("{get_input="); 
+                       if (getInputIndex > -1) { 
+                               inputName = propertyName.substring(getInputIndex+11, propertyName.length()-1); 
+                       } 
+               }
+               
+               return inputName;
+       }
+       
        
        protected static Timestamp getCurrentTimeStamp() {
                
@@ -2036,3 +2365,4 @@ public class ToscaResourceInstaller {
        }
 
 }
+