diff options
Diffstat (limited to 'asdc-controller/src/main')
10 files changed, 408 insertions, 59 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/ASDCControllerSingleton.java b/asdc-controller/src/main/java/org/onap/so/asdc/ASDCControllerSingleton.java index 0ed878446f..62971ecd2b 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/ASDCControllerSingleton.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/ASDCControllerSingleton.java @@ -22,22 +22,25 @@ package org.onap.so.asdc; import javax.annotation.PreDestroy; +import org.onap.so.asdc.client.ASDCConfiguration; import org.onap.so.asdc.client.ASDCController; import org.onap.so.asdc.client.exceptions.ASDCControllerException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Profile; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; - +import org.onap.so.logger.MsoLogger; import java.security.SecureRandom; + @Component @Profile("!test") public class ASDCControllerSingleton { @Autowired - private ASDCController asdcController; + private ASDCController asdcController; + private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.ASDC, ASDCControllerSingleton.class); @@ -49,8 +52,8 @@ public class ASDCControllerSingleton { asdcController.setControllerName("mso-controller"+randomNumber); asdcController.initASDC(); } catch (ASDCControllerException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + msoLogger.error(e); + } } @@ -59,8 +62,7 @@ public class ASDCControllerSingleton { try { asdcController.closeASDC (); } catch (ASDCControllerException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + msoLogger.error(e); } } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/WebSecurityConfigImpl.java b/asdc-controller/src/main/java/org/onap/so/asdc/WebSecurityConfigImpl.java index bbd7cc06e3..2383e7d810 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/WebSecurityConfigImpl.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/WebSecurityConfigImpl.java @@ -36,7 +36,7 @@ public class WebSecurityConfigImpl extends WebSecurityConfig { http.csrf().disable() .authorizeRequests() .antMatchers("/manage/health","/manage/info").permitAll() - .antMatchers("/**").hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(),",").toString()) + .antMatchers("/**").hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(),",")) .and() .httpBasic(); } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java index 0af1dedce4..ee329ced3c 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java @@ -269,7 +269,7 @@ public class ASDCController { - private IDistributionClientDownloadResult downloadTheArtifact (IArtifactInfo artifact, + protected IDistributionClientDownloadResult downloadTheArtifact (IArtifactInfo artifact, String distributionId) throws ASDCDownloadException { LOGGER.debug ("Trying to download the artifact : " + artifact.getArtifactURL () @@ -379,7 +379,7 @@ public class ASDCController { } - private void sendDeployNotificationsForResource(VfResourceStructure vfResourceStructure,DistributionStatusEnum distribStatus, String errorReason) { + protected void sendDeployNotificationsForResource(VfResourceStructure vfResourceStructure,DistributionStatusEnum distribStatus, String errorReason) { for (IArtifactInfo artifactInfo : vfResourceStructure.getResourceInstance().getArtifacts()) { @@ -406,7 +406,7 @@ public class ASDCController { } } - private void sendCsarDeployNotification(INotificationData iNotif, VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure, boolean deploySuccessful, String errorReason) { + protected void sendCsarDeployNotification(INotificationData iNotif, VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure, boolean deploySuccessful, String errorReason) { IArtifactInfo csarArtifact = toscaResourceStructure.getToscaArtifact(); @@ -433,7 +433,7 @@ public class ASDCController { } } - private void deployResourceStructure (VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure) throws ArtifactInstallerException { + protected void deployResourceStructure (VfResourceStructure resourceStructure, ToscaResourceStructure toscaResourceStructure) throws ArtifactInstallerException { LOGGER.info (MessageEnum.ASDC_START_DEPLOY_ARTIFACT, resourceStructure.getResourceInstance().getResourceInstanceName(), resourceStructure.getResourceInstance().getResourceUUID(), "ASDC"); try { @@ -468,7 +468,7 @@ public class ASDCController { DOWNLOAD, DEPLOY } - private void sendASDCNotification (NotificationType notificationType, + protected void sendASDCNotification (NotificationType notificationType, String artifactURL, String consumerID, String distributionID, @@ -524,7 +524,7 @@ public class ASDCController { LOGGER.recordMetricEvent (subStarttime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully sent notification to ASDC", "ASDC", action, null); } - private void sendFinalDistributionStatus ( + protected void sendFinalDistributionStatus ( String distributionID, DistributionStatusEnum status, String errorReason) { @@ -673,7 +673,7 @@ public class ASDCController { } } - private void processResourceNotification (INotificationData iNotif) { + protected void processResourceNotification (INotificationData iNotif) { // For each artifact, create a structure describing the VFModule in a ordered flat level VfResourceStructure resourceStructure = null; ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(); @@ -744,7 +744,7 @@ public class ASDCController { "Exception caught during Installation of artifact", "ASDC", "processResourceNotification", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in processResourceNotification", e); } } - private void processCsarServiceArtifacts (INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) { + protected void processCsarServiceArtifacts (INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) { List<IArtifactInfo> serviceArtifacts = iNotif.getServiceArtifacts(); @@ -777,7 +777,7 @@ public class ASDCController { } private static final String UNKNOWN="Unknown"; - + /** * @return the address of the ASDC we are connected to. */ diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/ResourceInstance.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/ResourceInstance.java index cfdff85bc3..9115ed3ef2 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/ResourceInstance.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/ResourceInstance.java @@ -24,7 +24,7 @@ import java.util.ArrayList; import org.onap.sdc.api.notification.IResourceInstance; -final class ResourceInstance implements IResourceInstance { +public class ResourceInstance implements IResourceInstance { @Override public String getResourceInstanceName(){ diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/DistributionClientEmulator.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/DistributionClientEmulator.java index 4f76d3fa17..1d07656012 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/DistributionClientEmulator.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/test/emulators/DistributionClientEmulator.java @@ -91,7 +91,6 @@ public class DistributionClientEmulator implements IDistributionClient { try { inputStream = getData(filename); } catch (IOException e) { - e.printStackTrace(); logger.debug("InputStream is NULL for:"+ resourcePath + filename); } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfModuleArtifact.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfModuleArtifact.java index adc8071454..92fc598e7d 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfModuleArtifact.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfModuleArtifact.java @@ -44,7 +44,15 @@ public final class VfModuleArtifact { public VfModuleArtifact(IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException { artifactInfo=artifactinfo; result = new String(clientResult.getArtifactPayload(), "UTF-8"); - + } + + public VfModuleArtifact(IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult, String modifiedHeatTemplate) throws UnsupportedEncodingException { + artifactInfo=artifactinfo; + if(modifiedHeatTemplate != null){ + result = modifiedHeatTemplate; + }else{ + result = new String(clientResult.getArtifactPayload(), "UTF-8"); + } } public HeatFiles getHeatFiles() { diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfResourceStructure.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfResourceStructure.java index a045c2bb3a..f5e45115fd 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfResourceStructure.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/VfResourceStructure.java @@ -102,6 +102,15 @@ public class VfResourceStructure { public void addArtifactToStructure(IDistributionClient distributionClient,IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult) throws UnsupportedEncodingException { VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo,clientResult); + addArtifactByType(artifactinfo,clientResult,vfModuleArtifact); + } + + public void addArtifactToStructure(IDistributionClient distributionClient,IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult, String modifiedHeatTemplate) throws UnsupportedEncodingException { + VfModuleArtifact vfModuleArtifact = new VfModuleArtifact(artifactinfo,clientResult,modifiedHeatTemplate); + addArtifactByType(artifactinfo,clientResult,vfModuleArtifact); + } + + protected void addArtifactByType(IArtifactInfo artifactinfo,IDistributionClientDownloadResult clientResult, VfModuleArtifact vfModuleArtifact) throws UnsupportedEncodingException { switch(artifactinfo.getArtifactType()) { case ASDCConfiguration.HEAT: diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java index 7dfb1bae3e..970cb0bf50 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java @@ -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; @@ -144,6 +152,9 @@ public class ToscaResourceInstaller { protected ServiceProxyResourceCustomizationRepository serviceProxyCustomizationRepo; @Autowired + protected ServiceProxyResourceRepository serviceProxyRepo; + + @Autowired protected CollectionResourceRepository collectionRepo; @Autowired @@ -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; @@ -370,32 +390,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 +456,54 @@ 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(); + + logger.debug("Comparing VFModuleMetadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID()); - Optional<org.onap.sdc.toscaparser.api.Group> matchingObject = vfGroups.stream(). - filter(group -> group.getMetadata().getValue("vfModuleModelCustomizationUUID").equals(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()); } service.getVnfCustomizations().add(vnfResource); - } + } } } @@ -698,9 +748,6 @@ public class ToscaResourceInstaller { spCustomizationResource.setServiceProxyResource(spResource); serviceProxyCustomizationSet.add(spCustomizationResource); - - spResource.setServiceProxyCustomization(serviceProxyCustomizationSet); - toscaResourceStructure.setCatalogServiceProxyResource(spResource); toscaResourceStructure.setCatalogServiceProxyResourceCustomization(spCustomizationResource); @@ -744,7 +791,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 +839,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) { @@ -1084,7 +1190,8 @@ public class ToscaResourceInstaller { 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){ @@ -1104,9 +1211,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; @@ -1210,6 +1491,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, diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java b/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java index 54977104ff..ab9c359b7f 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/util/ASDCNotificationLogging.java @@ -201,11 +201,6 @@ public class ASDCNotificationLogging { } } - buffer.append(System.lineSeparator()); - buffer.append(System.lineSeparator()); - buffer.append("VNF Level Properties:"); - buffer.append(System.lineSeparator()); - List<NodeTemplate> vfNodeTemplatesList = toscaResourceStructure.getSdcCsarHelper().getServiceVfList(); for (NodeTemplate vfNodeTemplate : vfNodeTemplatesList) { @@ -287,17 +282,16 @@ public class ASDCNotificationLogging { } - - - buffer.append(System.lineSeparator()); - buffer.append("VF Module Properties:"); - buffer.append(System.lineSeparator()); + List<Group> vfGroups = toscaResourceStructure.getSdcCsarHelper().getVfModulesByVf(testNull(vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))); for(Group group : vfGroups){ Metadata vfMetadata = group.getMetadata(); + buffer.append(System.lineSeparator()); + buffer.append("VF Module Properties:"); + buffer.append(System.lineSeparator()); buffer.append("ModelInvariantUuid:"); buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELINVARIANTUUID))); buffer.append(System.lineSeparator()); @@ -314,7 +308,62 @@ public class ASDCNotificationLogging { buffer.append(testNull(toscaResourceStructure.getSdcCsarHelper().getMetadataPropertyValue(vfMetadata, SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); buffer.append(System.lineSeparator()); } - + + List<NodeTemplate> cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(vfNodeTemplate, SdcTypes.CVFC); + + for(NodeTemplate cvfcTemplate : cvfcList) { + + buffer.append(System.lineSeparator()); + buffer.append("CVNFC Properties:"); + buffer.append(System.lineSeparator()); + buffer.append("ModelCustomizationUuid:"); + buffer.append(testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))); + buffer.append(System.lineSeparator()); + buffer.append("ModelInvariantUuid:"); + buffer.append(testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID))); + buffer.append(System.lineSeparator()); + buffer.append("ModelName:"); + buffer.append(testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); + buffer.append(System.lineSeparator()); + buffer.append("ModelUuid:"); + buffer.append(testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID))); + buffer.append(System.lineSeparator()); + buffer.append("ModelVersion:"); + buffer.append(testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); + buffer.append(System.lineSeparator()); + buffer.append("Description:"); + buffer.append(testNull(cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); + buffer.append(System.lineSeparator()); + + + List<NodeTemplate> vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC); + + for(NodeTemplate vfcTemplate : vfcList) { + buffer.append(System.lineSeparator()); + buffer.append("VNFC Properties:"); + buffer.append(System.lineSeparator()); + buffer.append("ModelCustomizationUuid:"); + buffer.append(testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID))); + buffer.append(System.lineSeparator()); + buffer.append("ModelInvariantUuid:"); + buffer.append(testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID))); + buffer.append(System.lineSeparator()); + buffer.append("ModelName:"); + buffer.append(testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_NAME))); + buffer.append(System.lineSeparator()); + buffer.append("ModelUuid:"); + buffer.append(testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID))); + buffer.append(System.lineSeparator()); + buffer.append("ModelVersion:"); + buffer.append(testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION))); + buffer.append(System.lineSeparator()); + buffer.append("Description:"); + buffer.append(testNull(vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); + buffer.append(System.lineSeparator()); + + } + + } } diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/util/YamlEditor.java b/asdc-controller/src/main/java/org/onap/so/asdc/util/YamlEditor.java index fdeddf1f68..32f512b0f0 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/util/YamlEditor.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/util/YamlEditor.java @@ -39,9 +39,9 @@ import org.onap.so.db.catalog.beans.HeatTemplateParam; public class YamlEditor { - private static final String REFER_PATTERN = "file:///"; - private Map <String, Object> yml; - private Yaml yaml = new Yaml (); + protected static final String REFER_PATTERN = "file:///"; + protected Map <String, Object> yml; + protected Yaml yaml = new Yaml (); public YamlEditor () { @@ -52,7 +52,7 @@ public class YamlEditor { } @SuppressWarnings("unchecked") - private synchronized void init (byte[] body) { + protected synchronized void init (byte[] body) { InputStream input = new ByteArrayInputStream (body); yml = (Map <String, Object>) yaml.load (input); } |