X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=asdc-controller%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fso%2Fasdc%2Finstaller%2Fheat%2FToscaResourceInstaller.java;h=bd5f0d0dbcbdb57a35523ea3001ff8ec823b8709;hb=560e84158798cb884de65e3cf33ab657f0e6e6df;hp=0e30b77b0103c9032c2fba7298afe340cd9a04a2;hpb=40396c8763a600059d025fb202802ac70d406b08;p=so.git 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 0e30b77b01..bd5f0d0dbc 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 @@ -26,6 +26,7 @@ package org.onap.so.asdc.installer.heat; import java.sql.Timestamp; import java.util.ArrayList; +import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.HashSet; @@ -34,7 +35,10 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; +import com.google.common.base.Strings; import org.hibernate.exception.ConstraintViolationException; import org.hibernate.exception.LockAcquisitionException; import org.onap.sdc.api.notification.IArtifactInfo; @@ -46,16 +50,8 @@ import org.onap.sdc.tosca.parser.elements.queries.EntityQuery; import org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery; import org.onap.sdc.tosca.parser.enums.SdcTypes; import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; -import org.onap.sdc.toscaparser.api.CapabilityAssignment; -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.Property; -import org.onap.sdc.toscaparser.api.RequirementAssignment; -import org.onap.sdc.toscaparser.api.RequirementAssignments; +import org.onap.sdc.toscaparser.api.*; import org.onap.sdc.toscaparser.api.elements.Metadata; -import org.onap.sdc.toscaparser.api.elements.StatefulEntityType; import org.onap.sdc.toscaparser.api.functions.GetInput; import org.onap.sdc.toscaparser.api.parameters.Input; import org.onap.sdc.utils.DistributionStatusEnum; @@ -70,6 +66,7 @@ import org.onap.so.asdc.installer.ToscaResourceStructure; import org.onap.so.asdc.installer.VfModuleArtifact; import org.onap.so.asdc.installer.VfModuleStructure; import org.onap.so.asdc.installer.VfResourceStructure; +import org.onap.so.asdc.installer.bpmn.WorkflowResource; import org.onap.so.asdc.util.YamlEditor; import org.onap.so.db.catalog.beans.AllottedResource; import org.onap.so.db.catalog.beans.AllottedResourceCustomization; @@ -84,6 +81,7 @@ import org.onap.so.db.catalog.beans.HeatEnvironment; import org.onap.so.db.catalog.beans.HeatFiles; import org.onap.so.db.catalog.beans.HeatTemplate; import org.onap.so.db.catalog.beans.HeatTemplateParam; +import org.onap.so.db.catalog.beans.InstanceGroup; import org.onap.so.db.catalog.beans.InstanceGroupType; import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; import org.onap.so.db.catalog.beans.NetworkInstanceGroup; @@ -111,6 +109,8 @@ import org.onap.so.db.catalog.data.repository.ConfigurationResourceCustomization 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.HeatEnvironmentRepository; +import org.onap.so.db.catalog.data.repository.HeatFilesRepository; 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; @@ -120,9 +120,9 @@ import org.onap.so.db.catalog.data.repository.PnfResourceRepository; import org.onap.so.db.catalog.data.repository.ServiceProxyResourceCustomizationRepository; import org.onap.so.db.catalog.data.repository.ServiceRepository; import org.onap.so.db.catalog.data.repository.TempNetworkHeatTemplateRepository; +import org.onap.so.db.catalog.data.repository.ToscaCsarRepository; 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; @@ -142,6 +142,7 @@ import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.util.CollectionUtils; @Component public class ToscaResourceInstaller { @@ -225,6 +226,12 @@ public class ToscaResourceInstaller { @Autowired protected HeatTemplateRepository heatRepo; + @Autowired + protected HeatEnvironmentRepository heatEnvRepo; + + @Autowired + protected HeatFilesRepository heatFilesRepo; + @Autowired protected NetworkResourceCustomizationRepository networkCustomizationRepo; @@ -241,26 +248,59 @@ public class ToscaResourceInstaller { @Autowired protected ExternalServiceToInternalServiceRepository externalServiceToInternalServiceRepository; + @Autowired + protected ToscaCsarRepository toscaCsarRepo; + @Autowired protected PnfResourceRepository pnfResourceRepository; @Autowired protected PnfCustomizationRepository pnfCustomizationRepository; + @Autowired + protected WorkflowResource workflowResource; + protected static final Logger logger = LoggerFactory.getLogger(ToscaResourceInstaller.class); - public boolean isResourceAlreadyDeployed(VfResourceStructure vfResourceStruct) throws ArtifactInstallerException { + public boolean isCsarAlreadyDeployed(ToscaResourceStructure toscaResourceStructure) + throws ArtifactInstallerException { + boolean deployed = false; + if (toscaResourceStructure == null) { + return deployed; + } + + IArtifactInfo inputToscaCsar = toscaResourceStructure.getToscaArtifact(); + String checkSum = inputToscaCsar.getArtifactChecksum(); + String artifactUuid = inputToscaCsar.getArtifactUUID(); + + Optional toscaCsarObj = toscaCsarRepo.findById(artifactUuid); + if (toscaCsarObj.isPresent()) { + ToscaCsar toscaCsar = toscaCsarObj.get(); + if (!toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) { + String errorMessage = + String.format("Csar with UUID: %s already exists.Their checksums don't match", artifactUuid); + throw new ArtifactInstallerException(errorMessage); + } else if (toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) { + deployed = true; + } + } + return deployed; + } + + public boolean isResourceAlreadyDeployed(ResourceStructure vfResourceStruct, boolean serviceDeployed) + throws ArtifactInstallerException { boolean status = false; - VfResourceStructure vfResourceStructure = vfResourceStruct; + ResourceStructure vfResourceStructure = vfResourceStruct; try { status = vfResourceStructure.isDeployedSuccessfully(); } catch (RuntimeException e) { status = false; + logger.debug("Exception :", e); } try { Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID()); - if (existingService != null) + if (existingService != null && !serviceDeployed) status = true; if (status) { logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(), @@ -285,8 +325,8 @@ public class ToscaResourceInstaller { } return status; } catch (Exception e) { - logger.error("{} {} {}", MessageEnum.ASDC_ARTIFACT_CHECK_EXC.toString(), ErrorCode.SchemaError.getValue(), - "Exception - isResourceAlreadyDeployed"); + logger.error(Strings.repeat("{} ", 3), MessageEnum.ASDC_ARTIFACT_CHECK_EXC.toString(), + ErrorCode.SchemaError.getValue(), "Exception - isResourceAlreadyDeployed"); throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e); } } @@ -307,6 +347,7 @@ public class ToscaResourceInstaller { } } + @Transactional(rollbackFor = {ArtifactInstallerException.class}) public void installTheResource(ToscaResourceStructure toscaResourceStruct, ResourceStructure resourceStruct) throws ArtifactInstallerException { @@ -355,7 +396,7 @@ public class ToscaResourceInstaller { if (dbExceptionToCapture instanceof ConstraintViolationException || dbExceptionToCapture instanceof LockAcquisitionException) { - logger.warn("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(), + logger.warn(Strings.repeat("{} ", 5), MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(), resourceStruct.getResourceInstance().getResourceName(), resourceStruct.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(), "Exception - ASCDC Artifact already deployed", e); @@ -363,7 +404,7 @@ public class ToscaResourceInstaller { String elementToLog = (!artifactListForLogging.isEmpty() ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString() : "No element listed"); - logger.error("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog, + logger.error(Strings.repeat("{} ", 4), MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog, ErrorCode.DataError.getValue(), "Exception caught during installation of " + resourceStruct.getResourceInstance().getResourceName() + ". Transaction rollback", e); @@ -386,22 +427,20 @@ public class ToscaResourceInstaller { List artifactListForLogging = new ArrayList<>(); try { createToscaCsar(toscaResourceStruct); - Service service = createService(toscaResourceStruct, vfResourceStruct); + createService(toscaResourceStruct, vfResourceStruct); + Service service = toscaResourceStruct.getCatalogService(); List vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList(); - for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { - Metadata metadata = nodeTemplate.getMetaData(); - String serviceType = toscaResourceStruct.getCatalogService().getServiceType(); String vfCustomizationCategory = toscaResourceStruct.getSdcCsarHelper() .getMetadataPropertyValue(metadata, SdcPropertyNames.PROPERTY_NAME_CATEGORY); processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata, vfCustomizationCategory); } + workflowResource.processWorkflows(vfResourceStructure); processResourceSequence(toscaResourceStruct, service); - processVFResources(toscaResourceStruct, service, vfResourceStructure); List allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources(); processAllottedResources(toscaResourceStruct, service, allottedResourceList); processNetworks(toscaResourceStruct, service); @@ -410,7 +449,9 @@ public class ToscaResourceInstaller { // Process Service Proxy & Configuration processServiceProxyAndConfiguration(toscaResourceStruct, service); - serviceRepo.save(service); + logger.info("Saving Service: {} ", service.getModelName()); + service = serviceRepo.save(service); + correlateConfigCustomResources(service); WatchdogComponentDistributionStatus status = new WatchdogComponentDistributionStatus( vfResourceStruct.getNotification().getDistributionID(), MSO); @@ -434,7 +475,7 @@ public class ToscaResourceInstaller { if (dbExceptionToCapture instanceof ConstraintViolationException || dbExceptionToCapture instanceof LockAcquisitionException) { - logger.warn("{} {} {} {} {}", MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(), + logger.warn(Strings.repeat("{} ", 5), MessageEnum.ASDC_ARTIFACT_ALREADY_DEPLOYED.toString(), vfResourceStructure.getResourceInstance().getResourceName(), vfResourceStructure.getNotification().getServiceVersion(), ErrorCode.DataError.getValue(), "Exception - ASCDC Artifact already deployed", e); @@ -442,7 +483,7 @@ public class ToscaResourceInstaller { String elementToLog = (!artifactListForLogging.isEmpty() ? artifactListForLogging.get(artifactListForLogging.size() - 1).toString() : "No element listed"); - logger.error("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog, + logger.error(Strings.repeat("{} ", 4), MessageEnum.ASDC_ARTIFACT_INSTALL_EXC.toString(), elementToLog, ErrorCode.DataError.getValue(), "Exception caught during installation of " + vfResourceStructure.getResourceInstance().getResourceName() @@ -458,7 +499,7 @@ public class ToscaResourceInstaller { List getRequirementList(List resultList, List nodeTemplates, ISdcCsarHelper iSdcCsarHelper) { - List nodes = new ArrayList(); + List nodes = new ArrayList<>(); nodes.addAll(nodeTemplates); for (NodeTemplate nodeTemplate : nodeTemplates) { @@ -489,12 +530,12 @@ public class ToscaResourceInstaller { // This method retrieve resource sequence from csar file void processResourceSequence(ToscaResourceStructure toscaResourceStructure, Service service) { - List resouceSequence = new ArrayList(); - List resultList = new ArrayList(); + List resouceSequence = new ArrayList<>(); + List resultList = new ArrayList<>(); ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper(); List nodeTemplates = iSdcCsarHelper.getServiceNodeTemplates(); - List nodes = new ArrayList(); + List nodes = new ArrayList<>(); nodes.addAll(nodeTemplates); for (NodeTemplate nodeTemplate : nodeTemplates) { @@ -520,27 +561,31 @@ public class ToscaResourceInstaller { logger.debug(" resourceSeq for service uuid(" + service.getModelUUID() + ") : " + resourceSeqStr); } - private static String getValue(Object value, List servInputs) { - String output = null; + + // this of temporary solution + private static String getValue(Object value, List inputs) { + String outInput; + String defaultValue = null; if (value instanceof Map) { - // currently this logic handles only one level of nesting. - return ((LinkedHashMap) value).values().toArray()[0].toString(); + outInput = ((LinkedHashMap) value).values().toArray()[0].toString(); } else if (value instanceof GetInput) { String inputName = ((GetInput) value).getInputName(); - - for (Input input : servInputs) { - if (input.getName().equals(inputName)) { - // keep both input name and default value - // if service input does not supplies value the use default value - String defaultValue = input.getDefault() != null ? (String) input.getDefault().toString() : ""; - output = inputName + "|" + defaultValue;// return default value - } + Optional inputOptional = + inputs.stream().filter(input -> input.getName().equals(inputName)).findFirst(); + if (inputOptional.isPresent()) { + Input input = inputOptional.get(); + defaultValue = input.getDefault() != null ? input.getDefault().toString() : ""; } - + // Gets a value between [ and ] + String regex = "\\[.*?\\]"; + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(value.toString()); + String valueStr = matcher.find() ? matcher.group() : inputName; + outInput = valueStr + "|" + defaultValue; } else { - output = value != null ? value.toString() : ""; + outInput = value != null ? value.toString() : ""; } - return output; // return property value + return outInput; } String getResourceInput(ToscaResourceStructure toscaResourceStructure, String resourceCustomizationUuid) @@ -638,7 +683,8 @@ public class ToscaResourceInstaller { } protected ConfigurationResourceCustomization getConfigurationResourceCustomization(NodeTemplate nodeTemplate, - ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization) { + ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization, + Service service) { Metadata metadata = nodeTemplate.getMetaData(); ConfigurationResource configResource = getConfigurationResource(nodeTemplate); @@ -651,41 +697,25 @@ public class ToscaResourceInstaller { .setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); configCustomizationResource.setModelInstanceName(nodeTemplate.getName()); - configCustomizationResource.setNfFunction(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)); - configCustomizationResource.setNfRole(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFROLE)); - configCustomizationResource.setNfType(toscaResourceStructure.getSdcCsarHelper() - .getNodeTemplatePropertyLeafValue(nodeTemplate, SdcPropertyNames.PROPERTY_NAME_NFTYPE)); + configCustomizationResource.setFunction( + toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "function")); + configCustomizationResource.setRole( + toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "role")); + configCustomizationResource.setType( + toscaResourceStructure.getSdcCsarHelper().getNodeTemplatePropertyLeafValue(nodeTemplate, "type")); configCustomizationResource .setServiceProxyResourceCustomizationUUID(spResourceCustomization.getModelCustomizationUUID()); configCustomizationResource.setConfigurationResource(configResource); + configCustomizationResource.setService(service); configResourceCustomizationSet.add(configCustomizationResource); configResource.setConfigurationResourceCustomization(configResourceCustomizationSet); + return configCustomizationResource; } - protected Optional getVnrNodeTemplate( - List configurationNodeTemplatesList, ToscaResourceStructure toscaResourceStructure, - ServiceProxyResourceCustomization spResourceCustomization) { - Optional configurationResourceCust = Optional.empty(); - for (NodeTemplate nodeTemplate : configurationNodeTemplatesList) { - StatefulEntityType entityType = nodeTemplate.getTypeDefinition(); - String type = entityType.getType(); - - if (VLAN_NETWORK_RECEPTOR.equals(type)) { - configurationResourceCust = Optional.of(getConfigurationResourceCustomization(nodeTemplate, - toscaResourceStructure, spResourceCustomization)); - break; - } - } - - return configurationResourceCust; - } - protected void processServiceProxyAndConfiguration(ToscaResourceStructure toscaResourceStruct, Service service) { List serviceProxyResourceList = @@ -694,9 +724,8 @@ public class ToscaResourceInstaller { List configurationNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceNodeTemplateBySdcType(SdcTypes.CONFIGURATION); - List serviceProxyList = new ArrayList(); - List configurationResourceList = - new ArrayList(); + List serviceProxyList = new ArrayList<>(); + List configurationResourceList = new ArrayList<>(); ServiceProxyResourceCustomization serviceProxy = null; @@ -704,8 +733,6 @@ public class ToscaResourceInstaller { for (NodeTemplate spNode : serviceProxyResourceList) { serviceProxy = createServiceProxy(spNode, service, toscaResourceStruct); serviceProxyList.add(serviceProxy); - Optional vnrResourceCustomization = - getVnrNodeTemplate(configurationNodeTemplatesList, toscaResourceStruct, serviceProxy); for (NodeTemplate configNode : configurationNodeTemplatesList) { @@ -713,19 +740,21 @@ public class ToscaResourceInstaller { toscaResourceStruct.getSdcCsarHelper().getRequirementsOf(configNode).getAll(); for (RequirementAssignment requirement : requirementsList) { if (requirement.getNodeTemplateName().equals(spNode.getName())) { - ConfigurationResourceCustomization configurationResource = createConfiguration(configNode, - toscaResourceStruct, serviceProxy, vnrResourceCustomization); - - Optional matchingObject = configurationResourceList - .stream() - .filter(configurationResourceCustomization -> configNode.getMetaData() - .getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID) - .equals(configurationResource.getModelCustomizationUUID())) - .findFirst(); + ConfigurationResourceCustomization configurationResource = + createConfiguration(configNode, toscaResourceStruct, serviceProxy, service); + + Optional matchingObject = + configurationResourceList.stream() + .filter(configurationResourceCustomization -> configNode.getMetaData() + .getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID) + .equals(configurationResource.getModelCustomizationUUID())) + .filter(configurationResourceCustomization -> configurationResourceCustomization + .getModelInstanceName() + .equals(configurationResource.getModelInstanceName())) + .findFirst(); if (!matchingObject.isPresent()) { configurationResourceList.add(configurationResource); } - break; } } @@ -738,6 +767,37 @@ public class ToscaResourceInstaller { service.setServiceProxyCustomizations(serviceProxyList); } + /* + * ConfigurationResourceCustomization objects have their IDs auto incremented in the database. Unless we know their + * IDs we cannot possibly associate their related records. So these ConfigResourceCustomizations are persisted first + * and subsequently correlated. + */ + + protected void correlateConfigCustomResources(Service service) { + /* Assuming that we have only one pair of VRF-VNR */ + ConfigurationResourceCustomization vrfConfigCustomResource = null; + ConfigurationResourceCustomization vnrConfigCustomResource = null; + List configCustomList = service.getConfigurationCustomizations(); + for (ConfigurationResourceCustomization configResource : configCustomList) { + String nodeType = configResource.getConfigurationResource().getToscaNodeType(); + if (NODES_VRF_ENTRY.equalsIgnoreCase(nodeType)) { + vrfConfigCustomResource = configResource; + } else if (VLAN_NETWORK_RECEPTOR.equalsIgnoreCase(nodeType)) { + vnrConfigCustomResource = configResource; + } + } + + if (vrfConfigCustomResource != null) { + vrfConfigCustomResource.setConfigResourceCustomization(vnrConfigCustomResource); + configCustomizationRepo.save(vrfConfigCustomResource); + + } + if (vnrConfigCustomResource != null) { + vnrConfigCustomResource.setConfigResourceCustomization(vrfConfigCustomResource); + configCustomizationRepo.save(vnrConfigCustomResource); + } + } + protected void processNetworkCollections(ToscaResourceStructure toscaResourceStruct, Service service) { List networkCollectionList = @@ -762,48 +822,6 @@ public class ToscaResourceInstaller { } - protected void processVFResources(ToscaResourceStructure toscaResourceStruct, Service service, - VfResourceStructure vfResourceStructure) throws Exception { - logger.debug("processVFResources"); - - List vfNodeTemplatesList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList(); - // String servicecategory = toscaResourceStruct.getCatalogService().getCategory(); - // String serviceType = toscaResourceStruct.getCatalogService().getServiceType(); - - for (NodeTemplate nodeTemplate : vfNodeTemplatesList) { - Metadata metadata = nodeTemplate.getMetaData(); - String vfCustomizationCategory = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY); - logger.debug("VF Category is : " + vfCustomizationCategory); - - // Do not treat Allotted Resources as VNF resources - if (ALLOTTED_RESOURCE.equalsIgnoreCase(vfCustomizationCategory)) { - continue; - } - - String vfCustomizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); - logger.debug("VFCustomizationUUID=" + vfCustomizationUUID); - - IResourceInstance vfNotificationResource = vfResourceStructure.getResourceInstance(); - - // 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())) { - logger.debug("vfCustomizationUUID: " + vfCustomizationUUID - + " matches vfNotificationResource CustomizationUUID"); - - processVfModules(toscaResourceStruct, vfResourceStructure, service, nodeTemplate, metadata, - vfCustomizationCategory); - } else { - logger.debug("Notification VF ResourceCustomizationUUID: " - + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " - + "Tosca VF Customization UUID: " + vfCustomizationUUID); - } - } - } /** * This is used to process the PNF specific resource, including resource and resource_customization. @@ -960,8 +978,8 @@ public class ToscaResourceInstaller { VnfResourceCustomization vnfResource = createVnfResource(nodeTemplate, toscaResourceStruct, service); - Set existingCvnfcSet = new HashSet(); - Set existingVnfcSet = new HashSet(); + Set existingCvnfcSet = new HashSet<>(); + Set existingVnfcSet = new HashSet<>(); for (VfModuleStructure vfModuleStructure : vfResourceStructure.getVfModuleStructure()) { @@ -1003,8 +1021,15 @@ public class ToscaResourceInstaller { vnfcInstanceGroupCustomizationRepo.saveAndFlush(vnfcInstanceGroupCustomization); } - - service.getVnfCustomizations().add(vnfResource); + List seqResult = processVNFCGroupSequence(toscaResourceStruct, groupList); + if (!CollectionUtils.isEmpty(seqResult)) { + String resultStr = seqResult.stream().collect(Collectors.joining(",")); + vnfResource.setVnfcInstanceGroupOrder(resultStr); + logger.debug( + "vnfcGroupOrder result for service uuid(" + service.getModelUUID() + ") : " + resultStr); + } + // add this vnfResource with existing vnfResource for this service + addVnfCustomization(service, vnfResource); } else { logger.debug("Notification VF ResourceCustomizationUUID: " + vfNotificationResource.getResourceCustomizationUUID() + " doesn't match " @@ -1013,6 +1038,85 @@ public class ToscaResourceInstaller { } } + private List processVNFCGroupSequence(ToscaResourceStructure toscaResourceStructure, + List groupList) { + if (CollectionUtils.isEmpty(groupList)) { + return Collections.emptyList(); + } + + ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper(); + List strSequence = new ArrayList<>(groupList.size()); + List tempGroupList = new ArrayList<>(groupList.size()); + List nodes = new ArrayList<>(); + tempGroupList.addAll(groupList); + + for (Group group : groupList) { + List nodeList = group.getMemberNodes(); + boolean hasRequirements = false; + for (NodeTemplate node : nodeList) { + RequirementAssignments requirements = iSdcCsarHelper.getRequirementsOf(node); + if (requirements != null && requirements.getAll() != null && !requirements.getAll().isEmpty()) { + hasRequirements = true; + break; + } + } + + if (!hasRequirements) { + strSequence.add(group.getName()); + tempGroupList.remove(group); + nodes.addAll(nodeList); + } + } + + getVNFCGroupSequenceList(strSequence, tempGroupList, nodes, iSdcCsarHelper); + + return strSequence; + + } + + private void getVNFCGroupSequenceList(List strSequence, List groupList, List nodes, + ISdcCsarHelper iSdcCsarHelper) { + if (CollectionUtils.isEmpty(groupList)) { + return; + } + + List tempGroupList = new ArrayList<>(); + tempGroupList.addAll(groupList); + + for (Group group : groupList) { + ArrayList members = group.getMemberNodes(); + for (NodeTemplate memberNode : members) { + boolean isAllExists = true; + RequirementAssignments requirements = iSdcCsarHelper.getRequirementsOf(memberNode); + if (requirements == null || requirements.getAll() == null || requirements.getAll().isEmpty()) { + continue; + } + List rqaList = requirements.getAll(); + for (RequirementAssignment rqa : rqaList) { + String name = rqa.getNodeTemplateName(); + for (NodeTemplate node : nodes) { + if (name.equals(node.getName())) { + break; + } + } + + isAllExists = false; + break; + } + + if (isAllExists) { + strSequence.add(group.getName()); + tempGroupList.remove(group); + nodes.addAll(group.getMemberNodes()); + } + } + + if (!tempGroupList.isEmpty() && tempGroupList.size() < groupList.size()) { + getVNFCGroupSequenceList(strSequence, tempGroupList, nodes, iSdcCsarHelper); + } + } + } + public void processWatchdog(String distributionId, String servideUUID, Optional distributionNotification, String consumerId) { WatchdogServiceModVerIdLookup modVerIdLookup = @@ -1053,7 +1157,8 @@ public class ToscaResourceInstaller { break; case ASDCConfiguration.HEAT_NET: case ASDCConfiguration.OTHER: - logger.warn("{} {} {} {}", MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT.toString(), + case ASDCConfiguration.CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT: + logger.warn(Strings.repeat("{} ", 4), MessageEnum.ASDC_ARTIFACT_TYPE_NOT_SUPPORT.toString(), vfModuleArtifact.getArtifactInfo().getArtifactType() + "(Artifact Name:" + vfModuleArtifact.getArtifactInfo().getArtifactName() + ")", ErrorCode.DataError.getValue(), "Artifact type not supported"); @@ -1128,77 +1233,100 @@ public class ToscaResourceInstaller { protected void createHeatTemplateFromArtifact(VfResourceStructure vfResourceStructure, ToscaResourceStructure toscaResourceStruct, VfModuleArtifact vfModuleArtifact) { - HeatTemplate heatTemplate = new HeatTemplate(); - List typeList = new ArrayList<>(); - typeList.add(ASDCConfiguration.HEAT_NESTED); - typeList.add(ASDCConfiguration.HEAT_ARTIFACT); - heatTemplate.setTemplateBody( - verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList)); - heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName()); + HeatTemplate existingHeatTemplate = + heatRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) { - heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout()); - } else { - heatTemplate.setTimeoutMinutes(240); - } + if (existingHeatTemplate == null) { + HeatTemplate heatTemplate = new HeatTemplate(); + List typeList = new ArrayList<>(); + typeList.add(ASDCConfiguration.HEAT_NESTED); + typeList.add(ASDCConfiguration.HEAT_ARTIFACT); - heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); - heatTemplate.setVersion(BigDecimalVersion - .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); - heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + heatTemplate.setTemplateBody( + verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList)); + heatTemplate.setTemplateName(vfModuleArtifact.getArtifactInfo().getArtifactName()); - if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { - heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); + if (vfModuleArtifact.getArtifactInfo().getArtifactTimeout() != null) { + heatTemplate.setTimeoutMinutes(vfModuleArtifact.getArtifactInfo().getArtifactTimeout()); + } else { + heatTemplate.setTimeoutMinutes(240); + } + + heatTemplate.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); + heatTemplate.setVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); + heatTemplate.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + + if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { + heatTemplate.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); + } else { + heatTemplate.setArtifactChecksum(MANUAL_RECORD); + } + + Set heatParam = extractHeatTemplateParameters(vfModuleArtifact.getResult(), + vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + heatTemplate.setParameters(heatParam); + vfModuleArtifact.setHeatTemplate(heatTemplate); } else { - heatTemplate.setArtifactChecksum(MANUAL_RECORD); + vfModuleArtifact.setHeatTemplate(existingHeatTemplate); } - - Set heatParam = extractHeatTemplateParameters(vfModuleArtifact.getResult(), - vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - heatTemplate.setParameters(heatParam); - vfModuleArtifact.setHeatTemplate(heatTemplate); } protected void createHeatEnvFromArtifact(VfResourceStructure vfResourceStructure, VfModuleArtifact vfModuleArtifact) { - HeatEnvironment heatEnvironment = new HeatEnvironment(); - heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName()); - List typeList = new ArrayList<>(); - typeList.add(ASDCConfiguration.HEAT); - typeList.add(ASDCConfiguration.HEAT_VOL); - heatEnvironment.setEnvironment( - verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList)); - heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); - heatEnvironment.setVersion(BigDecimalVersion - .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); - heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - - if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { - heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); + + HeatEnvironment existingHeatEnvironment = + heatEnvRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + + if (existingHeatEnvironment == null) { + HeatEnvironment heatEnvironment = new HeatEnvironment(); + heatEnvironment.setName(vfModuleArtifact.getArtifactInfo().getArtifactName()); + List typeList = new ArrayList<>(); + typeList.add(ASDCConfiguration.HEAT); + typeList.add(ASDCConfiguration.HEAT_VOL); + heatEnvironment.setEnvironment( + verifyTheFilePrefixInArtifacts(vfModuleArtifact.getResult(), vfResourceStructure, typeList)); + heatEnvironment.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); + heatEnvironment.setVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); + heatEnvironment.setArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + + if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { + heatEnvironment.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); + } else { + heatEnvironment.setArtifactChecksum(MANUAL_RECORD); + } + vfModuleArtifact.setHeatEnvironment(heatEnvironment); } else { - heatEnvironment.setArtifactChecksum(MANUAL_RECORD); + vfModuleArtifact.setHeatEnvironment(existingHeatEnvironment); } - vfModuleArtifact.setHeatEnvironment(heatEnvironment); } protected void createHeatFileFromArtifact(VfResourceStructure vfResourceStructure, VfModuleArtifact vfModuleArtifact, ToscaResourceStructure toscaResourceStruct) { - HeatFiles heatFile = new HeatFiles(); - heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); - heatFile.setFileBody(vfModuleArtifact.getResult()); - heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName()); - heatFile.setVersion(BigDecimalVersion - .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); - toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); - if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { - heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); + HeatFiles existingHeatFiles = + heatFilesRepo.findByArtifactUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + + if (existingHeatFiles == null) { + HeatFiles heatFile = new HeatFiles(); + heatFile.setAsdcUuid(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + heatFile.setDescription(vfModuleArtifact.getArtifactInfo().getArtifactDescription()); + heatFile.setFileBody(vfModuleArtifact.getResult()); + heatFile.setFileName(vfModuleArtifact.getArtifactInfo().getArtifactName()); + heatFile.setVersion(BigDecimalVersion + .castAndCheckNotificationVersionToString(vfModuleArtifact.getArtifactInfo().getArtifactVersion())); + toscaResourceStruct.setHeatFilesUUID(vfModuleArtifact.getArtifactInfo().getArtifactUUID()); + if (vfModuleArtifact.getArtifactInfo().getArtifactChecksum() != null) { + heatFile.setArtifactChecksum(vfModuleArtifact.getArtifactInfo().getArtifactChecksum()); + } else { + heatFile.setArtifactChecksum(MANUAL_RECORD); + } + vfModuleArtifact.setHeatFiles(heatFile); } else { - heatFile.setArtifactChecksum(MANUAL_RECORD); + vfModuleArtifact.setHeatFiles(existingHeatFiles); } - vfModuleArtifact.setHeatFiles(heatFile); } protected Service createService(ToscaResourceStructure toscaResourceStructure, @@ -1272,22 +1400,15 @@ public class ToscaResourceInstaller { protected ConfigurationResourceCustomization createConfiguration(NodeTemplate nodeTemplate, ToscaResourceStructure toscaResourceStructure, ServiceProxyResourceCustomization spResourceCustomization, - Optional vnrResourceCustomization) { + Service service) { - ConfigurationResourceCustomization configCustomizationResource = - getConfigurationResourceCustomization(nodeTemplate, toscaResourceStructure, spResourceCustomization); + ConfigurationResourceCustomization configCustomizationResource = getConfigurationResourceCustomization( + nodeTemplate, toscaResourceStructure, spResourceCustomization, service); ConfigurationResource configResource = getConfigurationResource(nodeTemplate); Set configResourceCustomizationSet = new HashSet<>(); - StatefulEntityType entityType = nodeTemplate.getTypeDefinition(); - String type = entityType.getType(); - - if (NODES_VRF_ENTRY.equals(type)) { - configCustomizationResource.setConfigResourceCustomization(vnrResourceCustomization.orElse(null)); - } - configCustomizationResource.setConfigurationResource(configResource); configResourceCustomizationSet.add(configCustomizationResource); @@ -1396,6 +1517,7 @@ public class ToscaResourceInstaller { networkCustomizationRepo.saveAndFlush(networkResourceCustomization); + } else if (networkResourceCustomization == null) { networkResourceCustomization = createNetworkResourceCustomization(networkNodeTemplate, toscaResourceStructure); @@ -1532,7 +1654,7 @@ public class ToscaResourceInstaller { List networkInstanceGroupList = new ArrayList<>(); List collectionResourceInstanceGroupCustomizationList = - new ArrayList(); + new ArrayList<>(); for (Group group : groupList) { @@ -1695,16 +1817,25 @@ public class ToscaResourceInstaller { VnfResourceCustomization vnfResourceCustomization, ToscaResourceStructure toscaResourceStructure) { Metadata instanceMetadata = group.getMetadata(); - // Populate InstanceGroup + + InstanceGroup existingInstanceGroup = + instanceGroupRepo.findByModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + VFCInstanceGroup vfcInstanceGroup = new VFCInstanceGroup(); - vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); - 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.setRole("SUB-INTERFACE"); // Set Role - vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type + if (existingInstanceGroup == null) { + // Populate InstanceGroup + vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + 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.setRole("SUB-INTERFACE"); // Set Role + vfcInstanceGroup.setType(InstanceGroupType.VNFC); // Set type + } else { + vfcInstanceGroup = (VFCInstanceGroup) existingInstanceGroup; + } // Populate VNFCInstanceGroupCustomization VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization(); @@ -1730,11 +1861,65 @@ public class ToscaResourceInstaller { .getNodeTemplatePropertyLeafValue(vnfcNodeTemplate, getInputName)); vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup); + ArrayList inputs = vnfcNodeTemplate.getSubMappingToscaTemplate().getInputs(); + createVFCInstanceGroupMembers(vfcInstanceGroupCustom, group, inputs); return vfcInstanceGroupCustom; } + private void createVFCInstanceGroupMembers(VnfcInstanceGroupCustomization vfcInstanceGroupCustom, Group group, + List inputList) { + List members = group.getMemberNodes(); + if (!CollectionUtils.isEmpty(members)) { + for (NodeTemplate vfcTemplate : members) { + VnfcCustomization vnfcCustomization = new VnfcCustomization(); + + Metadata metadata = vfcTemplate.getMetaData(); + vnfcCustomization + .setModelCustomizationUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)); + vnfcCustomization.setModelInstanceName(vfcTemplate.getName()); + vnfcCustomization.setModelUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); + vnfcCustomization + .setModelInvariantUUID(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)); + vnfcCustomization.setModelVersion(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)); + vnfcCustomization.setModelName(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME)); + vnfcCustomization.setToscaNodeType(testNull(vfcTemplate.getType())); + vnfcCustomization + .setDescription(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION))); + vnfcCustomization.setResourceInput(getVnfcResourceInput(vfcTemplate, inputList)); + vfcInstanceGroupCustom.getVnfcCustomizations().add(vnfcCustomization); + } + } + } + + public String getVnfcResourceInput(NodeTemplate vfcTemplate, List inputList) { + Map resouceRequest = new HashMap<>(); + LinkedHashMap vfcTemplateProperties = vfcTemplate.getProperties(); + for (String key : vfcTemplateProperties.keySet()) { + Property property = vfcTemplateProperties.get(key); + String resourceValue = getValue(property.getValue(), inputList); + resouceRequest.put(key, resourceValue); + } + + String resourceCustomizationUuid = + vfcTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + + String jsonStr = null; + try { + ObjectMapper objectMapper = new ObjectMapper(); + jsonStr = objectMapper.writeValueAsString(resouceRequest); + jsonStr = jsonStr.replace("\"", "\\\""); + logger.debug("vfcResource request for resource customization id (" + resourceCustomizationUuid + ") : " + + jsonStr); + } catch (JsonProcessingException e) { + logger.debug("Json Exception: {}", e.getMessage()); + logger.error("Exception occurred", e); + } + + return jsonStr; + } + protected VfModuleCustomization createVFModuleResource(Group group, NodeTemplate vfTemplate, ToscaResourceStructure toscaResourceStructure, VfResourceStructure vfResourceStructure, IVfModuleData vfModuleData, VnfResourceCustomization vnfResource, Service service, @@ -1764,10 +1949,9 @@ public class ToscaResourceInstaller { // * Extract VFC's and CVFC's then add them to VFModule // ****************************************************************************************************************** - Set cvnfcConfigurationCustomizations = - new HashSet(); - Set cvnfcCustomizations = new HashSet(); - Set vnfcCustomizations = new HashSet(); + Set cvnfcConfigurationCustomizations = new HashSet<>(); + Set cvnfcCustomizations = new HashSet<>(); + Set vnfcCustomizations = new HashSet<>(); // Only set the CVNFC if this vfModule group is a member of it. List groupMembers = @@ -2083,14 +2267,14 @@ public class ToscaResourceInstaller { if (matchingObject.isPresent()) { List heatFilesList = new ArrayList<>(); - List volumeHeatChildTemplates = new ArrayList(); - List heatChildTemplates = new ArrayList(); + List volumeHeatChildTemplates = new ArrayList<>(); + List heatChildTemplates = new ArrayList<>(); HeatTemplate parentHeatTemplate = new HeatTemplate(); String parentArtifactType = null; Set artifacts = new HashSet<>(matchingObject.get().getVfModuleMetadata().getArtifacts()); for (VfModuleArtifact vfModuleArtifact : vfResourceStructure.getArtifactsMapByUUID().values()) { - List childNestedHeatTemplates = new ArrayList(); + List childNestedHeatTemplates = new ArrayList<>(); if (artifacts.contains(vfModuleArtifact.getArtifactInfo().getArtifactUUID())) { checkVfModuleArtifactType(vfModule, vfModuleCustomization, heatFilesList, vfModuleArtifact, @@ -2150,10 +2334,12 @@ public class ToscaResourceInstaller { vfModuleCustomization.setVolumeHeatEnv(volVfModuleArtifact.getHeatEnvironment()); vfModuleArtifact.incrementDeployedInDB(); } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ENV)) { - if (vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) { - vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment()); - } else { - vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment()); + if (vfModuleArtifact.getHeatEnvironment() != null) { + if (vfModuleArtifact.getHeatEnvironment().getName().contains("volume")) { + vfModuleCustomization.setVolumeHeatEnv(vfModuleArtifact.getHeatEnvironment()); + } else { + vfModuleCustomization.setHeatEnvironment(vfModuleArtifact.getHeatEnvironment()); + } } vfModuleArtifact.incrementDeployedInDB(); } else if (vfModuleArtifact.getArtifactInfo().getArtifactType().equals(ASDCConfiguration.HEAT_ARTIFACT)) { @@ -2166,20 +2352,25 @@ public class ToscaResourceInstaller { } protected VnfResourceCustomization createVnfResource(NodeTemplate vfNodeTemplate, - ToscaResourceStructure toscaResourceStructure, Service service) { + ToscaResourceStructure toscaResourceStructure, Service service) throws ArtifactInstallerException { VnfResourceCustomization vnfResourceCustomization = null; if (vnfResourceCustomization == null) { VnfResource vnfResource = findExistingVnfResource(service, vfNodeTemplate.getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)); - if (vnfResource == null) + if (vnfResource == null) { vnfResource = createVnfResource(vfNodeTemplate); + } vnfResourceCustomization = createVnfResourceCustomization(vfNodeTemplate, toscaResourceStructure, vnfResource); vnfResourceCustomization.setVnfResources(vnfResource); vnfResourceCustomization.setService(service); - vnfResource.getVnfResourceCustomizations().add(vnfResourceCustomization); + + // setting resource input for vnf customization + vnfResourceCustomization.setResourceInput( + getResourceInput(toscaResourceStructure, vnfResourceCustomization.getModelCustomizationUUID())); + service.getVnfCustomizations().add(vnfResourceCustomization); } return vnfResourceCustomization; @@ -2249,6 +2440,13 @@ public class ToscaResourceInstaller { } + if (vnfResourceCustomization.getMinInstances() == null && vnfResourceCustomization.getMaxInstances() == null) { + vnfResourceCustomization.setMinInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_MININSTANCES))); + vnfResourceCustomization.setMaxInstances(Integer.getInteger(toscaResourceStructure.getSdcCsarHelper() + .getNodeTemplatePropertyLeafValue(vfNodeTemplate, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES))); + } + toscaResourceStructure.setCatalogVnfResourceCustomization(vnfResourceCustomization); return vnfResourceCustomization; @@ -2393,7 +2591,7 @@ public class ToscaResourceInstaller { if (object == null) { return null; - } else if (object.equals("NULL")) { + } else if ("NULL".equals(object)) { return null; } else if (object instanceof Integer) { return object.toString(); @@ -2461,6 +2659,19 @@ public class ToscaResourceInstaller { return inputName; } + // this method add provided vnfCustomization to service with + // existing customization available in db. + private void addVnfCustomization(Service service, VnfResourceCustomization vnfResourceCustomization) { + List services = serviceRepo.findByModelUUID(service.getModelUUID()); + if (!services.isEmpty()) { + // service exist in db + Service existingService = services.get(0); + List vnfCustomizations = existingService.getVnfCustomizations(); + vnfCustomizations.forEach(e -> service.getVnfCustomizations().add(e)); + } + service.getVnfCustomizations().add(vnfResourceCustomization); + } + protected static Timestamp getCurrentTimeStamp() {