From 69455a268648881f4b5a0c4547d769c2e6ecc2c1 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Tue, 4 Sep 2018 11:21:02 -0400 Subject: added generic fabric support to SO Fix Autoincrement of ID field in table Fix accidental removal of method Update usage of requestdb client removed unused imports in common tasks and test Fix broken branch, have unit tests pass references the Epic branch Fix broken branch from compiling committing classpath for vfc adapter cause its not going away added in the fail case for when there are no profiles removed second set of adapters in application test yml removed double adapters in request db application test added jpa repo dependency to the so bpmn folder pom add creation timestamp column to the table added in null checks for Config returned from policy switched to string in requestprocess with jenerate switched to string in requestprocess with jenerate updated aai version in common pom to 605 from 591 renamed the db scripts for flyway sync to register added endpoint to application test yml for failing test ... Change-Id: I800f837ea75d7cdff740dc3a387e4d7654cfd085 Issue-ID: SO-972 Signed-off-by: Benjamin, Max (mb388a) --- .../org/onap/so/asdc/ASDCControllerSingleton.java | 1 - .../org/onap/so/asdc/client/ASDCController.java | 18 +- .../org/onap/so/asdc/client/ResourceInstance.java | 2 +- .../onap/so/asdc/installer/VfModuleArtifact.java | 10 +- .../so/asdc/installer/VfResourceStructure.java | 9 + .../installer/heat/ToscaResourceInstaller.java | 272 +++++++++++++++++++-- .../java/org/onap/so/asdc/util/YamlEditor.java | 8 +- 7 files changed, 290 insertions(+), 30 deletions(-) (limited to 'asdc-controller/src/main/java/org') 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 471a08bf99..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 @@ -15,7 +15,6 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * Modifications Copyright (C) 2018 IBM. * ============LICENSE_END========================================================= */ 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 55a437f2c0..fae3a49910 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 @@ -268,7 +268,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 () @@ -370,7 +370,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()) { @@ -397,7 +397,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(); @@ -424,7 +424,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 { @@ -459,7 +459,7 @@ public class ASDCController { DOWNLOAD, DEPLOY } - private void sendASDCNotification (NotificationType notificationType, + protected void sendASDCNotification (NotificationType notificationType, String artifactURL, String consumerID, String distributionID, @@ -515,7 +515,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) { @@ -664,7 +664,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(); @@ -735,7 +735,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 serviceArtifacts = iNotif.getServiceArtifacts(); @@ -768,7 +768,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/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..70831bc828 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,12 +85,16 @@ 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; @@ -101,6 +107,7 @@ 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; @@ -151,6 +158,9 @@ public class ToscaResourceInstaller { @Autowired protected ConfigurationResourceCustomizationRepository configCustomizationRepo; + + @Autowired + protected ConfigurationResourceRepository configRepo; @Autowired protected VnfResourceRepository vnfRepo; @@ -166,6 +176,12 @@ public class ToscaResourceInstaller { @Autowired protected VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo; + + @Autowired + protected VnfcCustomizationRepository vnfcCustomizationRepo; + + @Autowired + protected CvnfcCustomizationRepository cvnfcCustomizationRepo; @Autowired protected AllottedResourceRepository allottedRepo; @@ -420,40 +436,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 (!vfCustomizationCategory.equalsIgnoreCase(ALLOTTED_RESOURCE)) + 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 cvnfcCustomizations = new HashSet(); + Set vnfcCustomizations = new HashSet(); + + for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) { + + logger.debug("vfModuleStructure:" + vfModuleStructure.toString()); List vfGroups = toscaResourceStruct .getSdcCsarHelper().getVfModulesByVf(vfCustomizationUUID); - IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata(); + IVfModuleData vfMetadata = vfModuleStructure.getVfModuleMetadata(); + + logger.debug("Comparing VFModule Metadata CustomizationUUID : " + vfMetadata.getVfModuleModelCustomizationUUID()); + for(Group group : vfGroups){ + logger.debug("To Group VFModuleModelCustomizationUUID " + group.getMetadata().getValue("vfModuleModelCustomizationUUID")); + } Optional matchingObject = vfGroups.stream(). 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, cvnfcCustomizations, vnfcCustomizations); vfModuleCustomization.getVfModule().setVnfResources(vnfResource.getVnfResources()); }else throw new Exception("Cannot find matching VFModule Customization for VF Module Metadata: " + vfMetadata.getVfModuleModelCustomizationUUID()); } service.getVnfCustomizations().add(vnfResource); - } + } } } @@ -744,7 +777,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 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 +825,34 @@ public class ToscaResourceInstaller { toscaResourceStructure.setCatalogToscaCsar(toscaCsar); } + + protected VnfcCustomization findExistingVfc(Set 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 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 +1176,7 @@ 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 cvnfcCustomizations, Set vnfcCustomizations) { VfModuleCustomization vfModuleCustomization = findExistingVfModuleCustomization(vnfResource, vfModuleData.getVfModuleModelCustomizationUUID()); if(vfModuleCustomization == null){ @@ -1104,9 +1196,160 @@ public class ToscaResourceInstaller { vfResourceStructure.setAlreadyDeployed(true); } + //****************************************************************************************************************** + //* Extract VFC's and CVFC's then add them to VFModule + //****************************************************************************************************************** + + Set vnfVfmoduleCvnfcConfigurationCustomizations = new HashSet(); + + // Extract CVFC lists + List cvfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(nodeTemplate, SdcTypes.CVFC); + + for(NodeTemplate cvfcTemplate : cvfcList) { + + CvnfcCustomization existingCvnfcCustomization = findExistingCvfc(cvnfcCustomizations, cvfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + + if(existingCvnfcCustomization == null){ + + //Extract associated VFC - Should always be just one + List vfcList = toscaResourceStructure.getSdcCsarHelper().getNodeTemplateBySdcType(cvfcTemplate, SdcTypes.VFC); + + VnfcCustomization vnfcCustomization = new VnfcCustomization(); + VnfcCustomization existingVnfcCustomization = null; + + for(NodeTemplate vfcTemplate : vfcList) { + + existingVnfcCustomization = findExistingVfc(vnfcCustomizations, vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + + if(existingVnfcCustomization == null){ + 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); + } + + } + + 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); + + //***************************************************************************************************************************************** + //* Extract Fabric Configuration + //***************************************************************************************************************************************** + + List 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.setVnfcCustomization(vnfcCustomizations); + 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 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 VfModuleCustomization findExistingVfModuleCustomization(VnfResourceCustomization vnfResource, String vfModuleModelCustomizationUUID) { VfModuleCustomization vfModuleCustomization = null; @@ -1210,6 +1453,7 @@ public class ToscaResourceInstaller { protected void setHeatInformationForVfModule(ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure, VfModule vfModule, VfModuleCustomization vfModuleCustomization, Metadata vfMetadata) { + Optional 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/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 yml; - private Yaml yaml = new Yaml (); + protected static final String REFER_PATTERN = "file:///"; + protected Map 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 ) yaml.load (input); } -- cgit 1.2.3-korg