Remove Swagger UI
[so.git] / asdc-controller / src / main / java / org / onap / so / asdc / installer / heat / ToscaResourceInstaller.java
index 7dfb1ba..c8f7f05 100644 (file)
@@ -41,6 +41,7 @@ import org.onap.sdc.toscaparser.api.CapabilityAssignment;
 import org.onap.sdc.toscaparser.api.CapabilityAssignments;
 import org.onap.sdc.toscaparser.api.Group;
 import org.onap.sdc.toscaparser.api.NodeTemplate;
+import org.onap.sdc.toscaparser.api.Policy;
 import org.onap.sdc.toscaparser.api.RequirementAssignment;
 import org.onap.sdc.toscaparser.api.elements.Metadata;
 import org.onap.sdc.utils.DistributionStatusEnum;
@@ -62,6 +63,7 @@ import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
 import org.onap.so.db.catalog.beans.ConfigurationResource;
 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
+import org.onap.so.db.catalog.beans.CvnfcCustomization;
 import org.onap.so.db.catalog.beans.ExternalServiceToInternalService;
 import org.onap.so.db.catalog.beans.HeatEnvironment;
 import org.onap.so.db.catalog.beans.HeatFiles;
@@ -83,24 +85,30 @@ import org.onap.so.db.catalog.beans.VfModule;
 import org.onap.so.db.catalog.beans.VfModuleCustomization;
 import org.onap.so.db.catalog.beans.VnfResource;
 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
+import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization;
+import org.onap.so.db.catalog.beans.VnfcCustomization;
 import org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization;
 import org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository;
 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
 import org.onap.so.db.catalog.data.repository.CollectionResourceCustomizationRepository;
 import org.onap.so.db.catalog.data.repository.CollectionResourceRepository;
 import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomizationRepository;
+import org.onap.so.db.catalog.data.repository.ConfigurationResourceRepository;
+import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository;
 import org.onap.so.db.catalog.data.repository.ExternalServiceToInternalServiceRepository;
 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.ServiceProxyResourceCustomizationRepository;
+import org.onap.so.db.catalog.data.repository.ServiceProxyResourceRepository;
 import org.onap.so.db.catalog.data.repository.ServiceRepository;
 import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository;
 import org.onap.so.db.catalog.data.repository.VFModuleCustomizationRepository;
 import org.onap.so.db.catalog.data.repository.VFModuleRepository;
 import org.onap.so.db.catalog.data.repository.VnfCustomizationRepository;
 import org.onap.so.db.catalog.data.repository.VnfResourceRepository;
+import org.onap.so.db.catalog.data.repository.VnfcCustomizationRepository;
 import org.onap.so.db.catalog.data.repository.VnfcInstanceGroupCustomizationRepository;
 import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus;
 import org.onap.so.db.request.beans.WatchdogDistributionStatus;
@@ -143,6 +151,9 @@ public class ToscaResourceInstaller {
        @Autowired
        protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo;
        
+       @Autowired
+       protected ServiceProxyResourceRepository serviceProxyRepo;
+       
        @Autowired
        protected CollectionResourceRepository collectionRepo;
        
@@ -151,6 +162,9 @@ public class ToscaResourceInstaller {
        
        @Autowired
        protected ConfigurationResourceCustomizationRepository configCustomizationRepo;
+       
+       @Autowired
+       protected ConfigurationResourceRepository configRepo;
 
        @Autowired
        protected VnfResourceRepository vnfRepo;
@@ -166,6 +180,12 @@ public class ToscaResourceInstaller {
        
        @Autowired
        protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo;  
+       
+       @Autowired
+       protected VnfcCustomizationRepository vnfcCustomizationRepo;
+       
+       @Autowired
+       protected CvnfcCustomizationRepository cvnfcCustomizationRepo;
 
        @Autowired
        protected AllottedResourceRepository allottedRepo;
@@ -327,38 +347,47 @@ public class ToscaResourceInstaller {
                }
        }
 
-       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());
-                                       }
-                               } else {
-                                       throw new ArtifactInstallerException(
-                                                       "No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
-                                                                       + networkResourceModelName);
-                               }                                       
-                               
-                       }
-               }
+    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 ());
+                    }
+                } else {
+                    NetworkResourceCustomization networkCustomization = createNetwork (vlNode,
+                                                                                       toscaResourceStruct,
+                                                                                       null,
+                                                                                       null,
+                                                                                       null,
+                                                                                       service);
+                    service.getNetworkCustomizations().add (networkCustomization);
+                    logger.debug ("No NetworkResourceName found in TempNetworkHeatTemplateLookup for "
+                                  + networkResourceModelName);
+                }
+
+            }
+        }
        }
 
        protected void processAllottedResources(ToscaResourceStructure toscaResourceStruct, Service service,
@@ -370,32 +399,48 @@ public class ToscaResourceInstaller {
                        }
                }
        }
-       
+               
        protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) {
                
                List<NodeTemplate> serviceProxyResourceList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.SERVICE_PROXY);
                
                List<NodeTemplate> configurationNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION);
                
+               List<ServiceProxyResourceCustomization> serviceProxyList = new ArrayList<ServiceProxyResourceCustomization>();          
+               List<ConfigurationResourceCustomization> configurationResourceList = new ArrayList<ConfigurationResourceCustomization>();
+               
+               ServiceProxyResourceCustomization serviceProxy = null;
+               
                if (serviceProxyResourceList != null) {
                        for (NodeTemplate spNode : serviceProxyResourceList) {
-                               createServiceProxy(spNode, service, toscaResourceStruct);
-                               serviceProxyCustomizationRepo.saveAndFlush(toscaResourceStruct.getCatalogServiceProxyResourceCustomization());  
+                               serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct);
+                               
+                               ServiceProxyResource serviceProxyResource = findExistingServiceProxyResource(serviceProxyList, serviceProxy.getServiceProxyResource().getModelUUID());
+                               
+                               if(serviceProxyResource == null){
+                               
+                               serviceProxyList.add(serviceProxy);
 
                                for (NodeTemplate configNode : configurationNodeTemplatesList) {
-                                       
+                                                                               
                                                List<RequirementAssignment> requirementsList = toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll();
                                                for (RequirementAssignment requirement :  requirementsList) {
                                                        if (requirement.getNodeTemplateName().equals(spNode.getName())) {
-                                                               createConfiguration(configNode, toscaResourceStruct, toscaResourceStruct.getCatalogServiceProxyResourceCustomization());
-                                                               configCustomizationRepo.saveAndFlush(toscaResourceStruct.getCatalogConfigurationResourceCustomization());       
+                                                               ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, toscaResourceStruct, serviceProxy);
+                                                                                                                               
+                                                               configurationResourceList.add(configurationResource);
                                                                break;
                                                        }
                                                }
                                }
+                               
+                               }
        
                        }
                }
+               
+               service.setConfigurationCustomizations(configurationResourceList);
+               service.setServiceProxyCustomizations(serviceProxyList);
        }
        
        protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) {
@@ -420,40 +465,57 @@ public class ToscaResourceInstaller {
 
        protected void processVfModules(ToscaResourceStructure toscaResourceStruct, VfResourceStructure vfResourceStructure,
                        Service service, NodeTemplate nodeTemplate, Metadata metadata, String vfCustomizationCategory) throws Exception {
-               if (!vfCustomizationCategory.equalsIgnoreCase(ALLOTTED_RESOURCE)) 
+               
+               logger.debug("VF Category is : " + vfCustomizationCategory);
+               
+               if(vfResourceStructure.getVfModuleStructure() != null && !vfResourceStructure.getVfModuleStructure().isEmpty())
                {
 
                        String vfCustomizationUUID = toscaResourceStruct.getSdcCsarHelper()
                                        .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
-                       logger.debug("vfCustomizationUUID=" + vfCustomizationUUID);     
+                       logger.debug("VFCustomizationUUID=" + vfCustomizationUUID);     
                        
-                       IResourceInstance vfMetaDataResource = vfResourceStructure.getResourceInstance();               
+                       IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance();           
                        
-                       // Make sure the vfMetadata and tosca customizations match before comparing their VF Modules UUID's
-                       if(vfCustomizationUUID.equals(vfMetaDataResource.getResourceCustomizationUUID())){
-                               
-                               logger.debug("vfCustomizationUUID: " + vfCustomizationUUID + " matches vfMetaData CustomizationUUID");
+                       // 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);
+                       
+                       if(vfCustomizationUUID.equals(vfNotificationResource.getResourceCustomizationUUID())){
                                
-                               VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service);   
+                               logger.debug("vfCustomizationUUID: " + vfCustomizationUUID + " matches vfNotificationResource CustomizationUUID");
                        
-                               for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {                        
-                                       logger.debug("vfModuleStructure ModelUUID: " + vfModuleStructure.toString());
+                               VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service);
+                               
+                               Set<CvnfcCustomization> existingCvnfcSet = new HashSet<CvnfcCustomization>(); 
+                               Set<VnfcCustomization> existingVnfcSet = new HashSet<VnfcCustomization>();
+                                                               
+                               for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) {
+                                       
+                                       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();     
                                        
-                                       Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream().
-                                                   filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(vfMetadata.getVfModuleModelCustomizationUUID())).
-                                                   findFirst();
+                                       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();
                                        if(matchingObject.isPresent()){
-                                               VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct, vfResourceStructure,vfMetadata, vnfResource);
+                                               VfModuleCustomization vfModuleCustomization = createVFModuleResource(matchingObject.get(), nodeTemplate, toscaResourceStruct, 
+                                                                                                                                                                                        vfResourceStructure,vfMetadata, vnfResource, service, existingCvnfcSet, existingVnfcSet);
                                                vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources());
                                        }else
-                                               throw new Exception("Cannot find matching VFModule Customization for VF Module Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID());
+                                               throw new Exception("Cannot find matching VFModule Customization in Csar for Vf_Modules_Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID());
                                        
                                }
                                service.getVnfCustomizations().add(vnfResource);
-                  }
+                       } else{
+                               logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " +
+                                                    "Tosca VF Customization UUID: " +  vfCustomizationUUID);
+                       }
                }
        }
 
@@ -698,9 +760,6 @@ public class ToscaResourceInstaller {
                spCustomizationResource.setServiceProxyResource(spResource);
                serviceProxyCustomizationSet.add(spCustomizationResource);
 
-               
-               spResource.setServiceProxyCustomization(serviceProxyCustomizationSet);          
-               
                toscaResourceStructure.setCatalogServiceProxyResource(spResource);
                
                toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource);
@@ -744,7 +803,38 @@ public class ToscaResourceInstaller {
                
                return configCustomizationResource;
        }
+       
+       protected ConfigurationResourceCustomization createFabricConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure) {
+               
+               Metadata fabricMetadata = nodeTemplate.getMetaData();
+               
+               ConfigurationResource configResource = new ConfigurationResource();
+               
+               configResource.setModelName(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
+               configResource.setModelInvariantUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
+               configResource.setModelUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
+               configResource.setModelVersion(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
+               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;
+       }
 
        protected void createToscaCsar(ToscaResourceStructure toscaResourceStructure) {
                ToscaCsar toscaCsar = new ToscaCsar();
@@ -761,6 +851,34 @@ public class ToscaResourceInstaller {
 
                toscaResourceStructure.setCatalogToscaCsar(toscaCsar);
        }
+       
+       protected VnfcCustomization findExistingVfc(Set<VnfcCustomization> vnfcCustomizations, String customizationUUID) {
+               VnfcCustomization vnfcCustomization = null;
+               for(VnfcCustomization vnfcCustom : vnfcCustomizations){
+                       if (vnfcCustom != null && vnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
+                               vnfcCustomization = vnfcCustom;
+                       }
+               }
+               
+               if(vnfcCustomization==null)
+                       vnfcCustomization = vnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
+               
+               return vnfcCustomization;
+       }
+       
+       protected CvnfcCustomization findExistingCvfc(Set<CvnfcCustomization> cvnfcCustomizations, String customizationUUID) {
+               CvnfcCustomization cvnfcCustomization = null;
+               for(CvnfcCustomization cvnfcCustom : cvnfcCustomizations){
+                       if (cvnfcCustom != null && cvnfcCustom.getModelCustomizationUUID().equals(customizationUUID)) {
+                               cvnfcCustomization = cvnfcCustom;
+                       }
+               }
+               
+               if(cvnfcCustomization==null)
+                       cvnfcCustomization = cvnfcCustomizationRepo.findOneByModelCustomizationUUID(customizationUUID);
+               
+               return cvnfcCustomization;
+       }
 
        protected  NetworkResourceCustomization createNetwork(NodeTemplate networkNodeTemplate,
                        ToscaResourceStructure toscaResourceStructure, HeatTemplate heatTemplate, String aicMax, String aicMin,Service service) {
@@ -1044,7 +1162,7 @@ public class ToscaResourceInstaller {
                        vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
                        vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
                        vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
-               vfcInstanceGroup.setToscaNodeType(group.getType());
+                       vfcInstanceGroup.setToscaNodeType(group.getType());
                        vfcInstanceGroup.setRole("SUB-INTERFACE");   // Set Role
                        vfcInstanceGroup.setType(InstanceGroupType.VNFC);  // Set type  
                        
@@ -1061,30 +1179,11 @@ public class ToscaResourceInstaller {
                return vfcInstanceGroupCustom;
 
        }
-       
-       protected VFCInstanceGroup findExistingVnfcInstanceGroup(VnfResourceCustomization vnfResourceCustomization,
-                       String modelUUID) {
-               VFCInstanceGroup vfcInstanceGroup = null;
-               List<VnfcInstanceGroupCustomization> vnfInstanceGroupCustomizations = vnfResourceCustomization
-                               .getVnfcInstanceGroupCustomizations();
-               if(vnfInstanceGroupCustomizations != null){
-                       for (VnfcInstanceGroupCustomization vnfcInstanceGroupCustom : vnfResourceCustomization
-                                       .getVnfcInstanceGroupCustomizations()) {
-                               if (vnfcInstanceGroupCustom.getInstanceGroup() != null
-                                               && vnfcInstanceGroupCustom.getInstanceGroup().getModelUUID().equals(modelUUID)) {
-                                       vfcInstanceGroup = (VFCInstanceGroup)vnfcInstanceGroupCustom.getInstanceGroup();
-                               }
-                       }
-               }
-               if (vfcInstanceGroup == null)
-                       vfcInstanceGroup = (VFCInstanceGroup) instanceGroupRepo.findByModelUUID(modelUUID);
-
-               return vfcInstanceGroup;
-       }
-       
+               
        protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate nodeTemplate,
                        ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure,
-                       IVfModuleData vfModuleData, VnfResourceCustomization vnfResource) {
+                       IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, Set<CvnfcCustomization> existingCvnfcSet, Set<VnfcCustomization> existingVnfcSet) {
+               
                VfModuleCustomization vfModuleCustomization = findExistingVfModuleCustomization(vnfResource,
                                vfModuleData.getVfModuleModelCustomizationUUID());
                if(vfModuleCustomization == null){              
@@ -1094,7 +1193,7 @@ public class ToscaResourceInstaller {
                        if(vfModule==null)
                                vfModule=createVfModule(group, toscaResourceStructure, vfModuleData, vfMetadata);
                        
-                       vfModuleCustomization = createVfModuleCustomzation(group, toscaResourceStructure, vfModule, vfModuleData);
+                       vfModuleCustomization = createVfModuleCustomization(group, toscaResourceStructure, vfModule, vfModuleData);
                        setHeatInformationForVfModule(toscaResourceStructure, vfResourceStructure, vfModule, vfModuleCustomization,
                                        vfMetadata);
                        vfModuleCustomization.setVfModule(vfModule);
@@ -1104,9 +1203,183 @@ public class ToscaResourceInstaller {
                        vfResourceStructure.setAlreadyDeployed(true);
                }
                
+               //******************************************************************************************************************
+               //* Extract VFC's and CVFC's then add them to VFModule
+               //******************************************************************************************************************
+               
+               Set<VnfVfmoduleCvnfcConfigurationCustomization> vnfVfmoduleCvnfcConfigurationCustomizations = new HashSet<VnfVfmoduleCvnfcConfigurationCustomization>();                
+               Set<CvnfcCustomization> cvnfcCustomizations = new HashSet<CvnfcCustomization>();
+               Set<VnfcCustomization> vnfcCustomizations = new HashSet<VnfcCustomization>();
+
+               // Extract CVFC lists
+               List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CVFC);
+                                               
+               for(NodeTemplate cvfcTemplate : cvfcList) {
+                                                                       
+                       CvnfcCustomization existingCvnfcCustomization = findExistingCvfc(existingCvnfcSet, cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
+                       
+                       if(existingCvnfcCustomization == null){
+                       
+                       //Extract associated VFC - Should always be just one
+                       List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC);
+                                               
+                       for(NodeTemplate vfcTemplate : vfcList) {
+                               
+                               VnfcCustomization vnfcCustomization = new VnfcCustomization();
+                               VnfcCustomization existingVnfcCustomization = null;
+                               
+                               existingVnfcCustomization = findExistingVfc(existingVnfcSet, vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
+                                       
+                               // Only Add Abstract VNFC's to our DB, ignore all others
+                               if(existingVnfcCustomization == null && vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY).equalsIgnoreCase("Abstract")){
+                                       vnfcCustomization.setModelCustomizationUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
+                                       vnfcCustomization.setModelInstanceName(vfcTemplate.getName());
+                                       vnfcCustomization.setModelInvariantUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
+                                       vnfcCustomization.setModelName(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
+                                       vnfcCustomization.setModelUUID(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
+       
+                                       vnfcCustomization.setModelVersion(
+                                                       testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
+                                       vnfcCustomization.setDescription(
+                                                       testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION)));
+                                       vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType()));
+                                       
+                                       vnfcCustomizations.add(vnfcCustomization);
+                                       existingVnfcSet.add(vnfcCustomization);
+                               }
+                       
+                       // 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.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);
+                       
+                       //*****************************************************************************************************************************************
+                       //* Extract Fabric Configuration
+                       //*****************************************************************************************************************************************
+                       
+                       List<NodeTemplate> fabricConfigList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CONFIGURATION);
+                                                               
+                       for(NodeTemplate fabricTemplate : fabricConfigList) {
+                                                                               
+                               ConfigurationResource fabricConfig = null;
+                               
+                               ConfigurationResource existingConfig = findExistingConfiguration(service, fabricTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
+                                                               
+                               if(existingConfig == null){
+                                       
+                                       ConfigurationResourceCustomization fabricConfigCustomization = createFabricConfiguration(fabricTemplate, toscaResourceStructure);
+                                       
+                                       fabricConfig = fabricConfigCustomization.getConfigurationResource();
+                                       
+                                       service.getConfigurationCustomizations().add(fabricConfigCustomization);
+                               }else {
+                                       fabricConfig = existingConfig;
+                               }
+                               
+                               
+                               VnfVfmoduleCvnfcConfigurationCustomization vnfVfmoduleCvnfcConfigurationCustomization = createVfCnvfConfigCustomization(fabricTemplate, toscaResourceStructure, 
+                                                                                                                                                          vnfResource, vfModuleCustomization, cvnfcCustomization, fabricConfig);
+                               
+                               vnfVfmoduleCvnfcConfigurationCustomizations.add(vnfVfmoduleCvnfcConfigurationCustomization);
+                       }
+                       
+                       }
+                       
+                  }
+                       
+                 }
+                       
+               } 
+               
+               vfModuleCustomization.setCvnfcCustomization(cvnfcCustomizations);
+               vfModuleCustomization.setVnfVfmoduleCvnfcConfigurationCustomization(vnfVfmoduleCvnfcConfigurationCustomizations);
+               
                return vfModuleCustomization;
        }
        
+       protected VnfVfmoduleCvnfcConfigurationCustomization createVfCnvfConfigCustomization(NodeTemplate fabricTemplate, ToscaResourceStructure toscaResourceStruct, 
+            VnfResourceCustomization vnfResource, VfModuleCustomization vfModuleCustomization, CvnfcCustomization cvnfcCustomization,
+            ConfigurationResource configResource) {
+
+               Metadata fabricMetadata = fabricTemplate.getMetaData();
+               
+               
+               VnfVfmoduleCvnfcConfigurationCustomization vfModuleToCvnfc = new VnfVfmoduleCvnfcConfigurationCustomization();
+               
+               vfModuleToCvnfc.setConfigurationResource(configResource);
+               vfModuleToCvnfc.setCvnfcCustomization(cvnfcCustomization);
+               vfModuleToCvnfc.setModelCustomizationUUID(fabricMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
+               vfModuleToCvnfc.setModelInstanceName(fabricTemplate.getName());
+               vfModuleToCvnfc.setVfModuleCustomization(vfModuleCustomization);
+               vfModuleToCvnfc.setVnfResourceCustomization(vnfResource);
+               vfModuleToCvnfc.setPolicyName(toscaResourceStruct.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(fabricTemplate, "name"));
+               
+               List<Policy> policyList = toscaResourceStruct.getSdcCsarHelper().getPoliciesOfTarget(fabricTemplate);
+               
+               if(policyList != null){
+                       for(Policy policy : policyList){
+                               vfModuleToCvnfc.setPolicyName(policy.getName());
+                       }
+               }
+               
+               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));
+               
+               return vfModuleToCvnfc;
+       }
+               
+       protected ConfigurationResource findExistingConfiguration(Service service, String modelUUID) {
+               ConfigurationResource configResource = null;
+               for(ConfigurationResourceCustomization configurationResourceCustom : service.getConfigurationCustomizations()){
+                       if (configurationResourceCustom.getConfigurationResource() != null
+                                       && configurationResourceCustom.getConfigurationResource().getModelUUID().equals(modelUUID)) {
+                               configResource = configurationResourceCustom.getConfigurationResource();
+                       }
+               }
+               if(configResource==null)
+                       configResource = configRepo.findResourceByModelUUID(modelUUID);
+               
+               return configResource;
+       }
+       
+       protected ServiceProxyResource findExistingServiceProxyResource(List<ServiceProxyResourceCustomization> serviceProxyList, String modelUUID) {
+               ServiceProxyResource serviceProxyResource = null;
+               for(ServiceProxyResourceCustomization serviceProxyResourceCustom : serviceProxyList){
+                       if (serviceProxyResourceCustom.getServiceProxyResource() != null
+                                       && serviceProxyResourceCustom.getServiceProxyResource().getModelUUID().equals(modelUUID)) {
+                               serviceProxyResource = serviceProxyResourceCustom.getServiceProxyResource();
+                       }
+               }
+               if(serviceProxyResource==null)
+                       serviceProxyResource = serviceProxyRepo.findResourceByModelUUID(modelUUID);
+               
+               return serviceProxyResource;
+       }
+       
        protected VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource,
                        String vfModuleModelCustomizationUUID) {
                VfModuleCustomization vfModuleCustomization = null;
@@ -1135,7 +1408,7 @@ public class ToscaResourceInstaller {
                return vfModule;
        }
 
-       protected VfModuleCustomization createVfModuleCustomzation(Group group,
+       protected VfModuleCustomization createVfModuleCustomization(Group group,
                        ToscaResourceStructure toscaResourceStructure, VfModule vfModule, IVfModuleData vfModuleData) {
                VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
                
@@ -1210,6 +1483,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,
@@ -1321,16 +1595,10 @@ public class ToscaResourceInstaller {
                                
                        for (Group group : groupList) { 
                                
-                               VFCInstanceGroup vfcInstanceGroup = findExistingVnfcInstanceGroup(vnfResourceCustomization,
-                                               group.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
-                               if(vfcInstanceGroup == null){
-                                       VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(
-                                                       vfNodeTemplate, group, vnfResourceCustomization);
-                               
-                                       vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);
-                               }
-                       }
-                       
+                                       VnfcInstanceGroupCustomization vnfcInstanceGroupCustomization = createVNFCInstanceGroup(vfNodeTemplate, group, vnfResourceCustomization);
+                                       
+                                       vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization);                                
+                       }                       
                }
                return vnfResourceCustomization;
        }
@@ -1409,6 +1677,8 @@ public class ToscaResourceInstaller {
                                testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
                vnfResource.setAicVersionMin(
                                testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
+               vnfResource.setCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
+               vnfResource.setSubCategory(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY));
                
                return vnfResource;
        }